Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload a file into 2 folders and a mysql database.

Status
Not open for further replies.

C0FFEE123

Programmer
Sep 1, 2008
44
NL
Hello i have a question.

I want to upload a file into 2 folders and a mysql database.
I am getting the file through a <input type="file" />

I already got the send part only the part that is putting in it to a folder not yet.

How must i do it?
I would like to do it with a include into the form part.

Here is the code for the form:

<?php

//echo $_POST;

include_once '../includes/db.inc.php';
include_once 'admin.inc.php';

check_login();
top_admin('occasions', $pagina_titel);
open_db();
echo '<form action="occ_send.php" method="post"> <br />';

echo 'Artikel:';

<input type="text" name="artikel"> <br />';

echo 'Korte omschrijving:';

<input type="text" name="korte_omschrijving"> <br />';

echo 'Uitgebreide omschrijving:';

<input type="text" name="uitgebreide_omschrijving"> <br />';

echo 'Prijs:';

<input type="text" name="prijs"> <br />';

echo 'Plaatje:';

<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input type="file" name="plaatje"> <br />';

echo '<input type="submit" value="Invoeren"';
echo '</form>';

?>

And here is the code for the send to the database part:

<?php

//echo $_POST;

include_once '../includes/db.inc.php';
include_once 'admin.inc.php';
check_login();
top_admin('occasions', $pagina_titel);
open_db();

$sql="INSERT INTO occasion (occasion_name, occasion_short_description, occasion_long_description, occasion_price, occasion_picture)
VALUES
('$_POST[artikel]', '$_POST[korte_omschrijving]', '$_POST[uitgebreide_omschrijving]', '$_POST[prijs]', '$_POST[plaatje]')";
echo $sql . "<br />" . "<br />";
mysql_query($sql);

echo "1 artikel toegevoegd:" . "<br />";
echo "Artikel:" .$_POST['artikel'] . "<br />";
echo "Korte omschrijving:" .$_POST['korte_omschrijving'] . "<br />";
echo "Uitgebreide omschrijving:" .$_POST['uitgebreide_omschrijving'] . "<br />";
echo "Prijs:" .$_POST['prijs'] . "<br />";
echo "Plaatje:" .$_POST['plaatje'];

?>
 
something as simple as this should work

Code:
if (isset($_FILES['fieldname'])){
  writetofolder('foldername');
  writetofolder('secondfoldername');
  writetodatabase();
}
function writetofolder($foldername){
 if (!is_file($_FILES['fieldname']['tmp_name'])) return false;
 $f = copy ($_FILES['fieldname']['tmp_name'], $foldername . '/'.$_FILES['fieldname']['name']);
 return $f;
}
funtion writetodatabase(){
 $filecontents = file_get_contents($_FILES['fieldname']['tmp_name']);
 //remember to escape the file contents before inserting them into the database
}

you should also change this line as shown in red
Code:
echo '<form action="occ_send.php" method="post" [red]enctype="multipart/form-data"[/red]> <br />';
 
You mean with fieldname the name of the database field or the name of the file input bar?
 
you could get the answer to that from looking at the code. fieldname is the name of the file field in your html form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top