Jump to content

writing multiple file names to a mysql db in same row


nelquintin

Recommended Posts

I can get files to  upload to folder and add a new row for each in to a mysql db using the code below, how do I get all the filles in one row with multiple uploads

 

//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;


        }
     }
  }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.