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;


        }
     }
  }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.