DarkWater Posted July 5, 2008 Share Posted July 5, 2008 Remove the ; from the end of the MySQL query line. =P Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582283 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 Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582295 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? Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582299 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()); Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582302 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()); ?> Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582330 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()); } ?> Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582334 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 Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582341 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. Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582354 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. Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582358 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) } } Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582361 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. Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582362 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. Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582364 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()); ?> Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582365 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. Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582371 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 ; Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582375 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. Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582377 Share on other sites More sharing options...
sandbudd Posted July 5, 2008 Author Share Posted July 5, 2008 just a varchar? call it admin? Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582380 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. Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582386 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... Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582389 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)? Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582406 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? Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582408 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 Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582409 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. Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582410 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. Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582412 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? Link to comment https://forums.phpfreaks.com/topic/113310-solved-doesnt-upload/page/2/#findComment-582418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.