iPixel Posted October 1, 2007 Share Posted October 1, 2007 Im just making this really really simple upload image script. <? $action = isset($_POST['action']) ? $_POST['action'] : null; if (!is_null($action)) { $action = $_POST['action']; } if($action == "insert") // IF INSERT THEN UPLOAD THE IMAGE THAT WAS POSTED TO THIS POINT { $userfile_name = $_FILES['image']['name']; // filename $userfile_tmp = $_FILES['image']['tmp_name']; // temp filename $userfile_size = $_FILES['image']['size']; // file size $userfile_type = $_FILES['image']['type']; // file type... jpg, gif, etc... $directory = 'images/newsletters/'; // Directory where image will be uploaded to $prod_img = $direcroty . $userfile_name; // directory/imgname.jpg if (!empty($_FILES['image']['name'])) { move_uploaded_file($userfile_tmp, $prod_img); } else { echo "You did not chose an image to upload !"; } } else // IF NOT INSERT OR ANYTHING ELSE SHOW THE UPLOAD FORM { ?> <h2> Add e-Newsletter...</h2> <table cellpadding="3" cellspacing="0" border="0" style="border: 1px solid #CCCCCC; background-color: #EEEEEE;" width="20%"> <tr> <form action="admin_newsletters.php" method="post" enctype="multipart/form-data"> <td align="center"> <input type="file" name="image" /><br /> <input type="hidden" name="action" value="insert" /> <input type="submit" value="Upload eNewsletter" /> </td> </form> </tr> </table> <? } ?> And its not working ... im not sure why, i went to http://us.php.net/manual/en/function.move-uploaded-file.php and unless im blind it seems like this should work ? Any clue why it doesnt. all the folders for the directory are 777 so its not a permissions problem. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/71370-solved-move_uploaded_file-what-am-i-missing/ Share on other sites More sharing options...
shocker-z Posted October 1, 2007 Share Posted October 1, 2007 Try this just to see if it thinks the file has been moved.. <? $action = isset($_POST['action']) ? $_POST['action'] : null; if (!is_null($action)) { $action = $_POST['action']; } if($action == "insert") // IF INSERT THEN UPLOAD THE IMAGE THAT WAS POSTED TO THIS POINT { $userfile_name = $_FILES['image']['name']; // filename $userfile_tmp = $_FILES['image']['tmp_name']; // temp filename $userfile_size = $_FILES['image']['size']; // file size $userfile_type = $_FILES['image']['type']; // file type... jpg, gif, etc... $directory = 'images/newsletters/'; // Directory where image will be uploaded to $prod_img = $direcroty . $userfile_name; // directory/imgname.jpg if (!empty($_FILES['image']['name'])) { if(move_uploaded_file($userfile_tmp, $prod_img)) { echo 'uploaded'; } else { echo 'error uploading'; } } else { echo "You did not chose an image to upload !"; } } else // IF NOT INSERT OR ANYTHING ELSE SHOW THE UPLOAD FORM { ?> <h2> Add e-Newsletter...</h2> <table cellpadding="3" cellspacing="0" border="0" style="border: 1px solid #CCCCCC; background-color: #EEEEEE;" width="20%"> <tr> <form action="admin_newsletters.php" method="post" enctype="multipart/form-data"> <td align="center"> <input type="file" name="image" /><br /> <input type="hidden" name="action" value="insert" /> <input type="submit" value="Upload eNewsletter" /> </td> </form> </tr> </table> <? } ?> Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/71370-solved-move_uploaded_file-what-am-i-missing/#findComment-359144 Share on other sites More sharing options...
iPixel Posted October 1, 2007 Author Share Posted October 1, 2007 i get Error Uploading... Quote Link to comment https://forums.phpfreaks.com/topic/71370-solved-move_uploaded_file-what-am-i-missing/#findComment-359149 Share on other sites More sharing options...
shocker-z Posted October 1, 2007 Share Posted October 1, 2007 Try thisd i found a case that show's different errors <? $action = isset($_POST['action']) ? $_POST['action'] : null; if (!is_null($action)) { $action = $_POST['action']; } if($action == "insert") // IF INSERT THEN UPLOAD THE IMAGE THAT WAS POSTED TO THIS POINT { $userfile_name = $_FILES['image']['name']; // filename $userfile_tmp = $_FILES['image']['tmp_name']; // temp filename $userfile_size = $_FILES['image']['size']; // file size $userfile_type = $_FILES['image']['type']; // file type... jpg, gif, etc... $directory = 'images/newsletters/'; // Directory where image will be uploaded to $prod_img = $direcroty . $userfile_name; // directory/imgname.jpg if (!empty($_FILES['image']['name'])) { if(move_uploaded_file($userfile_tmp, $prod_img)) { echo 'uploaded'; } else { echo 'error uploading'; switch ($_FILES['uploadFile'] ['error']) { case 1: print '<p> The file is bigger than this PHP installation allows</p>'; break; case 2: print '<p> The file is bigger than this form allows</p>'; break; case 3: print '<p> Only part of the file was uploaded</p>'; break; case 4: print '<p> No file was uploaded</p>'; break; } } } else { echo "You did not chose an image to upload !"; } } else // IF NOT INSERT OR ANYTHING ELSE SHOW THE UPLOAD FORM { ?> <h2> Add e-Newsletter...</h2> <table cellpadding="3" cellspacing="0" border="0" style="border: 1px solid #CCCCCC; background-color: #EEEEEE;" width="20%"> <tr> <form action="admin_newsletters.php" method="post" enctype="multipart/form-data"> <td align="center"> <input type="file" name="image" /><br /> <input type="hidden" name="action" value="insert" /> <input type="submit" value="Upload eNewsletter" /> </td> </form> </tr> </table> <? } ?> Liam Quote Link to comment https://forums.phpfreaks.com/topic/71370-solved-move_uploaded_file-what-am-i-missing/#findComment-359160 Share on other sites More sharing options...
iPixel Posted October 1, 2007 Author Share Posted October 1, 2007 All i get is Error Uploading... none of the switch case errors appear. Quote Link to comment https://forums.phpfreaks.com/topic/71370-solved-move_uploaded_file-what-am-i-missing/#findComment-359169 Share on other sites More sharing options...
shocker-z Posted October 1, 2007 Share Posted October 1, 2007 sorry my bad change $_FILES['uploadFile'] ['error'] to $_FILES['image'] ['error'] Liam Quote Link to comment https://forums.phpfreaks.com/topic/71370-solved-move_uploaded_file-what-am-i-missing/#findComment-359170 Share on other sites More sharing options...
iPixel Posted October 1, 2007 Author Share Posted October 1, 2007 Heh i didnt catch that either... but non the less still the same result. Error Uploading and nothing else... Quote Link to comment https://forums.phpfreaks.com/topic/71370-solved-move_uploaded_file-what-am-i-missing/#findComment-359173 Share on other sites More sharing options...
iPixel Posted October 1, 2007 Author Share Posted October 1, 2007 i just ran it again with the print_r($_FILES); right after the Error Uploading echo.. here is the result ... error uploading Array ( [image] => Array ( [name] => 092707_TESTING.jpg [type] => image/pjpeg [tmp_name] => /tmp/phpfvufdS [error] => 0 => 17894 ) ) Quote Link to comment https://forums.phpfreaks.com/topic/71370-solved-move_uploaded_file-what-am-i-missing/#findComment-359204 Share on other sites More sharing options...
iPixel Posted October 1, 2007 Author Share Posted October 1, 2007 finally figured it out ... NOTE TO SELF : do not ever create variables named $directory, it *ux things up =0 Thanks for the help shocker-z Quote Link to comment https://forums.phpfreaks.com/topic/71370-solved-move_uploaded_file-what-am-i-missing/#findComment-359317 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.