rondog Posted March 13, 2008 Share Posted March 13, 2008 I cannot figure out why this isnt working...the folder 'uploads' is set to 777 also. Im sure this is something simple and im just not seeing it. It keeps coming back saying it wasnt uploaded. <?php if(isset($_POST['uploadbtn'])) { $fieldname = "thefile"; $filename = $_FILES[$fieldname]['name']; if ($filename != '') { $target = "uploads/"; $source = $_FILES[$fieldname]['tmp_name']; $moved = move_uploaded_file($source, $target); if($moved) { $status = "$filename has been successfully uploaded to $target"; } else { $status = "$filename wasn't uploaded."; } } } else { $status = "Please select a file."; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <h4><?=$status?></h4> <form id="form1" name="form1" enctype="multipart/form-data" method="post" action=""> <input type="file" name="thefile" id="thefile" /><br/> <input type="submit" name="uploadbtn" value="Upload" /> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/96058-simple-upload/ Share on other sites More sharing options...
digitalgod Posted March 13, 2008 Share Posted March 13, 2008 add this at the end of your first if statement echo "</br><pre>"; print_r( $_FILES ); if it says [errors] = 1 or something like that then you'll need to change your upload_max_filesize in php.ini, default is 2M Link to comment https://forums.phpfreaks.com/topic/96058-simple-upload/#findComment-491773 Share on other sites More sharing options...
rondog Posted March 13, 2008 Author Share Posted March 13, 2008 when I attempted to upload and wasn't successful, your snippet printed: Array ( [thefile] => Array ( [name] => thumb5.jpg [type] => image/jpeg [tmp_name] => /tmp/phpZxgLot [error] => 0 [size] => 5119 ) ) Link to comment https://forums.phpfreaks.com/topic/96058-simple-upload/#findComment-491782 Share on other sites More sharing options...
digitalgod Posted March 13, 2008 Share Posted March 13, 2008 hmm try replacing $target = "uploads/"; with $target = "uploads/" . $filename; // or try with the full path like this // $target = dirname(__FILE__) . "/uploads/" . $filename; Link to comment https://forums.phpfreaks.com/topic/96058-simple-upload/#findComment-491795 Share on other sites More sharing options...
rondog Posted March 13, 2008 Author Share Posted March 13, 2008 alright i did: $target = "uploads/" . $filename; and that worked..Thats very weird, I've never had that issue before. Thanks alot man. Link to comment https://forums.phpfreaks.com/topic/96058-simple-upload/#findComment-491799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.