DarkWater Posted July 5, 2008 Share Posted July 5, 2008 Remove the ; from the end of the MySQL query line. =P Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 now I get this and one file does upload instead of 2 Â Warning: move_uploaded_file(image/Hawaii2008 017.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/anodizi/public_html/image/upload2.php on line 44 Â Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpjQvFPO' to 'image/Hawaii2008 017.jpg' in /home/anodizi/public_html/image/upload2.php on line 44 Â Notice: Undefined variable: upload_feedback in /home/anodizi/public_html/image/upload2.php on line 51 Â Warning: move_uploaded_file(image/Hawaii2008 018.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/anodizi/public_html/image/upload2.php on line 44 Â Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpAC1WLq' to 'image/Hawaii2008 018.jpg' in /home/anodizi/public_html/image/upload2.php on line 44 Â Notice: Undefined variable: upload_feedback in /home/anodizi/public_html/image/upload2.php on line 51 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 Is there an upload directory in the image folder? And how are you looping to get both files? Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 DarkWater there is an upload directory in the image folder I am not sure how to loop them do I do something like  /* All of the uploaded images */ $attachment_1 = $_FILES["file1"]; $attachment_2 = $_FILES["file2"]; /* Destination directory */ $destination = "upload/"; /* Call the function to move the files */ move_upload( $attachment_1, $destination ); move_upload( $attachment_2, $destination ); ?> <?php mysql_query("INSERT INTO items(attachment) VALUES('$attachment_1')") ; mysql_query("INSERT INTO items(attachment) VALUES('$attachment_2')") ; or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 This code uploads both to the upload folder but only one in the db?  <?php error_reporting(E_ALL); ?> <?php $db_host = ''; $db_user = ''; $db_pwd = ''; $database = ''; $table = ''; $upload_feedback = ''; var_dump($_FILES); if (!mysql_connect($db_host, $db_user, $db_pwd))   die("Can't connect to database"); if (!mysql_select_db($database))   die("Can't select database"); $dest = 'upload/'; if(isset($_FILES) && !empty($_FILES) && is_array($_FILES)) {   foreach($_FILES as $file)   {     $upload_msg[$file['name']] = move_upload($file, $dest);   } }    function move_upload( $file, $dest, $overwrite = false )   {        if ($file["error"] == UPLOAD_ERR_OK)     {       if(!file_exists( $dest.$file["name"] ) || $overwrite)       {         if(move_uploaded_file( $file["tmp_name"], $dest.$file["name"] ))         {           $upload_feedback .= "The file " . $file["name"] . " was successfully uploaded";           $error      = FALSE;         }         else         {           $upload_feedback .= "The file " . $file["name"] . " could not be moved";           $error      = TRUE;         }       }       else       {         $upload_feedback .= "The file " . $file["name"] . " already exists, please check the overwrite option if you wish to replace it";         $error      = TRUE;       }     }     else     {       switch ($file["error"])       {         case UPLOAD_ERR_INI_SIZE:         case UPLOAD_ERR_FORM_SIZE:           $upload_feedback .= "The file " . $file["name"] . " is to large to be uploaded<br />";           $error      = TRUE;         break;         case UPLOAD_ERR_PARTIAL:           $upload_feedback .= "The file" . $file["name"] . " was interrupted while uploading, please try again<br />";           $error      = TRUE;         break;       }     }     return array( "error" => $error, "feedback" => $upload_feedback ); //return message plus error status   }   /* All of the uploaded images */   $attachment = $file['name'];   /* Call the function to move the files */   move_uploaded_file($file['tmp_name'],"image/upload/".$file['name']) ;    ?> <?php mysql_query("INSERT INTO `upload` (`attachment`) VALUES('{$attachment}')") or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 I didn't know you had that foreach on top. That explains a lot. You need to remove two lines near the bottom...I'll do it. Here: <?php error_reporting(E_ALL); ?> <?php $db_host = ''; $db_user = ''; $db_pwd = ''; $database = ''; $table = ''; $upload_feedback = ''; var_dump($_FILES); if (!mysql_connect($db_host, $db_user, $db_pwd))   die("Can't connect to database"); if (!mysql_select_db($database))   die("Can't select database"); $dest = 'upload/'; if(isset($_FILES) && !empty($_FILES) && is_array($_FILES)) {   foreach($_FILES as $file)   {     $upload_msg[$file['name']] = move_upload($file, $dest);   } }    function move_upload( $file, $dest, $overwrite = false )   {        if ($file["error"] == UPLOAD_ERR_OK)     {       if(!file_exists( $dest.$file["name"] ) || $overwrite)       {         if(move_uploaded_file( $file["tmp_name"], $dest.$file["name"] ))         {           $upload_feedback .= "The file " . $file["name"] . " was successfully uploaded";           $error      = FALSE;         }         else         {           $upload_feedback .= "The file " . $file["name"] . " could not be moved";           $error      = TRUE;         }       }       else       {         $upload_feedback .= "The file " . $file["name"] . " already exists, please check the overwrite option if you wish to replace it";         $error      = TRUE;       }     }     else     {       switch ($file["error"])       {         case UPLOAD_ERR_INI_SIZE:         case UPLOAD_ERR_FORM_SIZE:           $upload_feedback .= "The file " . $file["name"] . " is to large to be uploaded<br />";           $error      = TRUE;         break;         case UPLOAD_ERR_PARTIAL:           $upload_feedback .= "The file" . $file["name"] . " was interrupted while uploading, please try again<br />";           $error      = TRUE;         break;       }     }     return array( "error" => $error, "feedback" => $upload_feedback ); //return message plus error status   } ?> <?php foreach ($_FILES as $file) { mysql_query("INSERT INTO `upload` (`attachment`) VALUES('{$file['name']}')") or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 Dark Water wow we are close...lol... with that last code both went into the upload dir and both went into the database but with different id's. Do I need to change the database?   You Da Man Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 Well, is a user id supposed to go in there or something? They both shouldn't have the same file ID otherwise you can't reference them properly. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 Its going to be a requist form with the multiple upload capabilities. DarkWater as you can see I am not real good but I am learning fast..Please tell me the best way to do it..example file1, file2 etc. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 this is the array...that is why I asked should I have different fields in the db file1, file2, Â array(2) { ["file1"]=>Â array(5) { ["name"]=>Â string(18) "Hawaii2008 021.jpg" ["type"]=>Â string(10) "image/jpeg" ["tmp_name"]=>Â string(14) "/tmp/phpWo6Qjb" ["error"]=>Â int(0) ["size"]=>Â int(1312069) } ["file2"]=>Â array(5) { ["name"]=>Â string(18) "Hawaii2008 023.jpg" ["type"]=>Â string(10) "image/jpeg" ["tmp_name"]=>Â string(14) "/tmp/phpk7bgva" ["error"]=>Â int(0) ["size"]=>Â int(1356596) } } Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 Alright...is it just going to be like a "file upload" thing where you can just see all the files people uploaded? Ex: 1) John uploads somefile.jpg.  2) Joe checks your site, sees somefile.jpg, and wants it, so he downloads it.  Am I right? Then every file should have different IDs. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 no its a request for quote form that will only be seen by the admin. People upload thier prints for a quote but could have several of them and the admin needs to pull off of a display form and know which prints go to which. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 someone suggested this but I couldnt get it to work.... Â /* All of the uploaded images */ $attachment_1 = $_FILES["file1"]; $attachment_2 = $_FILES["file2"]; /* Destination directory */ $destination = "../upload/"; /* Call the function to move the files */ move_upload( $attachment_1, $destination ); move_upload( $attachment_2, $destination ); ?> <?php mysql_query("INSERT INTO items(attachment) VALUES('$attachment_1')") ; mysql_query("INSERT INTO items(attachment) VALUES('$attachment_2')") ; or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 Oh. Let me see your database schema. Like, how it's formatted. The current script works perfectly, the query might just need work. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 Table structure for table `upload` -- CREATE TABLE IF NOT EXISTS `upload` ( Â `id` int(10) NOT NULL auto_increment, Â `attachment` varchar(50) NOT NULL, Â PRIMARY KEYÂ (`id`) ) ENGINE=MyISAMÂ DEFAULT CHARSET=latin1 AUTO_INCREMENT=59 ; Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 You're also going to need a column to associate with what you're showing the admin. The files aren't directly related, they're only related by what they're associated to. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 just a varchar? call it admin? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 No....what are you exactly trying to do. Explain it to me as best as you can. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 K I will try...when the form was filled out I had it going just to a php write file and here is the test display results http://www.sandbudd.com/image/email.php now I need the same display but with a database and you can see that there can be multiple uploads... Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 Sorry, I took a shower and then the power died for a little bit. O_OÂ Â So, now, are you associating the files with a user, a specific album, or do you have SOME way of joining them other than giving the same ID (which is SUPPOSED to be unique)? Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 beats me didnt have the database before just wrote to a php file.... can we create multiple fields called file1,file2 and so on and have them go into those fields? Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 seems it would be simple to have the fields on the form as again form1,2,3 and uploading them and calling with the same id but I dont have the knowledge to do it Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 It may be simpler, but simpler isn't always better. What is the purpose of this file upload thing again? To show it to the admin or something? Just tell me one more time so I get it and can suggest a path. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 yes it is a request for quote form that someone would fill out and submit along with multiple file attachments that goes to a display results page...that is why I need the images that are uploaded for that person to be together. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 Does the person have a user id? Is there a way of identifying the person? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.