twilitegxa Posted July 11, 2009 Share Posted July 11, 2009 In the following script, the file APPEARS to be moved successfully (the message displays saying it has been moved successfully), but when I check the destination folder, the file has not been copied. Here is the form and script to move the file: Form: <html> <head> <title>A Simple File Upload Form</title> </head> <body> <form action="listing9.14.php" enctype="multipart/form-data" method="post"> <input type="hidden" name="max_file_size" value="51200" /> File To Upload: <input type="file" name="fileupload" /><br /><br /> <input type="submit" value="Upload!" /> </form> </body> </html> Upload: <html> <head> <title>A File Upload Script</title> </head> <body> <h1>File Upload Results</h1> <?php $file_dir = "/images"; foreach($_FILES as $file_name => $file_array) { print "path: ".$file_array['tmp_name']."<br>\n"; print "name: ".$file_array['name']."<br>\n"; print "type: ".$file_array['type']."<br>\n"; print "size: ".$file_array['size']."<br>\n"; if (is_uploaded_file($file_array['tmp_name'])) { move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("Couldn't copy"); print "file was moved!<br><br>"; } } ?> </body> </html> What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
AviNahum Posted July 11, 2009 Share Posted July 11, 2009 its 5:58 AM and i'm really tired lol... i didnt look at your code... but i made one a few weeks ago for my gallery so you can use it, i dont realy care.... <?php //+--------------------------------------------------------------------------------- // // ADD IMAGE // //+--------------------------------------------------------------------------------- function add_img() { global $DB, $cms, $std; $DB->query("SELECT * FROM cms_albums"); while ($a = $DB->fetch_row()) { $album_list .= '<option value="'.$a['id'].'">'.$a['name'].'</option>'; } //+--------------------------------------------------- // Start printing our HTML //+--------------------------------------------------- $html .= '<form ENCTYPE="multipart/form-data" action="'.$this->url.'&code=do_add_img" method="post">'; $html .= '<input type="file" name="image" size="35">'; $html .= '</form>'; return $html; } //---------------------------------------------------------------------------------------------- function do_add_img() { global $DB, $cms, $std; // Make some changes in the file name $random = rand(0,1000000000000000000); $_FILES["image"]["name"] = "".$random."_".$_FILES["image"]["name"].""; /*-------------------------------------------------------------------------*/ // Make some checks /*-------------------------------------------------------------------------*/ $type = $_FILES["image"]["type"]; $at = array("image/gif", "image/jpeg", "image/pjpeg", "image/png", "image/x-png"); // We allow only images file types if (! in_array($type, $at) ) { return $std->error("אתה מנסה לעלות תמונה שהיא לא בפורמט תקין."); } // If we got some errors in uploading, display it if ($_FILES["image"]["error"] > 0) { return $std->error("{$_FILES['image']['error']}"); } // If the file name alread exist, dispaly an error if (file_exists("".$this->dir."/" . $_FILES["image"]["name"])) { return $std->error("שם הקובץ כבר קיים בשרת, החלף את השם בשם חדש."); } /*-------------------------------------------------------------------------*/ // If we got here with no error, so just store the file /*-------------------------------------------------------------------------*/ move_uploaded_file($_FILES["image"]["tmp_name"], "".$this->dir."/" . $_FILES["image"]["name"]); } ?> there are some parts in hebrew but its only a error that might be displayed... it's works great Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 11, 2009 Author Share Posted July 11, 2009 I really appreciate the code, but I'm still pretty new to PHP and My SQL, so I'm trying to learn from a book to get started. In this tutorial, it doesn't seem to save the files uploaded to the database. Isn't that necessary? I'm not sure how this works, but your sample code seems like that's what it does as well. Quote Link to comment Share on other sites More sharing options...
xtopolis Posted July 11, 2009 Share Posted July 11, 2009 Your second argument for move_uploaded_file() looks weird. Try if (is_uploaded_file($file_array['tmp_name'])) { move_uploaded_file($file_array['tmp_name'], $file_dir . "/" . $file_array['name']) or die ("Couldn't copy"); print "file was moved!<br><br>"; } Though that may not change anything Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 11, 2009 Author Share Posted July 11, 2009 No, it still didn't do anything. :-( Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 13, 2009 Author Share Posted July 13, 2009 I'm going to close this topic because I found another script that works now. here is the link to the topic for it, if anyone runs across this post and needs it: http://www.phpfreaks.com/forums/index.php/topic,260097.msg1224453.html#msg1224453 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.