wrting multiple file names to a mysql db


#1

how do i write multiple files name to a mysql db at once after uploading images to a folder?
here is my code so far.
[php]

<?php //Check if the form was submitted. if(isset($_POST['uploadButton'])) { //Specify folder path where the file is going. $path = 'uploads/'; //Upload file one by one. foreach($_FILES['file']['name'] as $key => $val) { if($val != '') { $file_name = $_FILES['file']['name'][$key]; //Get file name. $file_tmp = $_FILES['file']['tmp_name'][$key]; //Get temporary file name. $file = $path . $file_name; //Move uploaded file if(move_uploaded_file($file_tmp, $file)) { echo 'File was succesfully uploaded to: ' . $file . '
'; } else { //Display error message if there was a problem uploading file. echo 'Error uploading file "' . $key . '."
'; } echo $target_path; $gallery = "upload/".basename( $_FILES['file']['name']); echo $gallery; $sql = "INSERT into images (imagePath) VALUES ('$gallery')"; mysql_query($sql) or die(mysql_error()); echo "Information added to the images table"; } } } } ?>

[/php]


#2

ive tried this as well. just need files in the same row
[php]

//Check if the form was submitted.
if(isset($_POST[‘uploadButton’])) {
//Specify folder path where the file is going.
$path = ‘uploads/’;

//Upload file one by one.
foreach($_FILES[‘file’][‘name’] as $key => $val) {
if($val != ‘’) {
$file_name = $_FILES[‘file’][‘name’][$key]; //Get file name.
$file_tmp = $_FILES[‘file’][‘tmp_name’][$key]; //Get temporary file name.
$file = $path . $file_name;
mysql_query(“INSERT INTO images (img1) VALUES(’$file’);”) or trigger_error('Unable to INsert: ’ . mysql_error());

  //Move uploaded file
  if(move_uploaded_file($file_tmp, $file)) {
    echo 'File was succesfully uploaded to: ' . $file . '<br />';
  } else {
    //Display error message if there was a problem uploading file.
    echo 'Error uploading file "' . $key . '."<br />';
  }

echo $target_path;

    }
 }

}

?>
[/php]


#3

Well, you nearly have it. But, first, what did you mean by you need files in one row? Did you mean you want to write one record with all the files in it? Is every file a separate entry into the database?

Basically, you would parse thru the files uploading them one at a time.
Then, if the upload is successful, you would write the record to the DB.
(You do not want to do it the other way in case the file does not make it to the server.)