Kasak Posted December 20, 2007 Share Posted December 20, 2007 Hi All - I am having problem in uploading image on server,This is the code can anyone guide where the problem is ? I would really appreciate it. here is upload-file.php <?php if (($_FILES['file']['type'] == "image/gif") || ($_FILES['file']['type'] == "image/jpeg") || ($_FILES['file']['type'] == "image/pjpeg") && ($_FILES['file']['size'] < 20000)) { if ($_FILES['file']['error'] > 0) { echo "Return Code: " . $_FILES['file']['error'] . "<br />"; } else { echo "Upload: " . $_FILES['file']['name'] . "<br />"; echo "Type: " . $_FILES['file']['type'] . "<br />"; echo "Size: " . ($_FILES['file']['size'] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES['file']['tmp_name'] . "<br />"; if (file_exists("/upload/" . $_FILES['file']['name'])) { echo $_FILES['file']['name'] . " already exists. "; echo "this is bad"; } else { move_uploaded_file($_FILES['file']['tmp_name'], "/upload/" . $_FILES['file']['name']); echo "Stored in: " . "/upload/" . $_FILES['file']['name']; } } } else { echo "Invalid file"; } ?> I have my upload file in web/upload it is running and not giving any errors but when I look in the folder upload I am not able to see anything. <html> <body> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/ Share on other sites More sharing options...
papaface Posted December 20, 2007 Share Posted December 20, 2007 Try changing: if (file_exists("/upload/" . $_FILES['file']['name'])) to if (file_exists("upload/" . $_FILES['file']['name'])) and move_uploaded_file($_FILES['file']['tmp_name'], "/upload/" . $_FILES['file']['name']); to move_uploaded_file($_FILES['file']['tmp_name'], "upload/" . $_FILES['file']['name']); Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419536 Share on other sites More sharing options...
adam291086 Posted December 20, 2007 Share Posted December 20, 2007 add in error_reporting(E_All); at the top of your code Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419537 Share on other sites More sharing options...
Kasak Posted December 20, 2007 Author Share Posted December 20, 2007 Yeah I did that too but it is not doing anything ....it says that it uploaded but when i check the specific folder image is not there can u suggest something else Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419540 Share on other sites More sharing options...
adam291086 Posted December 20, 2007 Share Posted December 20, 2007 have you tried echoing the file once uploaded. Make sure it is actually being uploaded Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419542 Share on other sites More sharing options...
redarrow Posted December 20, 2007 Share Posted December 20, 2007 your form needs help <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="__URL__" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419543 Share on other sites More sharing options...
papaface Posted December 20, 2007 Share Posted December 20, 2007 Have you made sure permissions are set correctly? Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419546 Share on other sites More sharing options...
Kasak Posted December 20, 2007 Author Share Posted December 20, 2007 this is what I am getting as output Upload: IMG_3279.jpg Type: image/jpeg Size: 924.536132812 Kb Temp file: /var/tmp/phpUTayWq Stored in: upload/IMG_3279.jpg but it does not upload to that folder Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419548 Share on other sites More sharing options...
adam291086 Posted December 20, 2007 Share Posted December 20, 2007 like the others said Posted on: Today at 11:19:20 AMPosted by: papaface Have you made sure permissions are set correctly? Posted on: Today at 11:18:33 AMPosted by: redarrow your form needs help Code: <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="__URL__" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419552 Share on other sites More sharing options...
Kasak Posted December 20, 2007 Author Share Posted December 20, 2007 <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> If I add this line it is giving error invalid file can anyone suggest me ..... chmod for uploading shld be wht 1777 Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419566 Share on other sites More sharing options...
~n[EO]n~ Posted December 20, 2007 Share Posted December 20, 2007 Try this PHP code, tweaked a little upload_file.php <?php $frfiletype = $_FILES['file']['type']; $frfilesize = $_FILES['file']['size']; $frfilename = $_FILES['file']['name']; $tmpName = $_FILES['file']['tmp_name']; $uploadDir = 'upload/'; $filePath = $uploadDir.$frfilename; if (($frfiletype == "image/gif") || ($frfiletype == "image/jpeg") || ($frfiletype == "image/pjpeg") && ($frfilesize < 20000)) { if ($_FILES['file']['error'] > 0) { echo "Return Code: " . $_FILES['file']['error'] . " "; } else { if (file_exists("upload/" . $frfilename)) { echo $frfilename . " already exists. "; echo "this is bad"; } else { move_uploaded_file($tmpName,$filePath); //move_uploaded_file($_FILES['file']['tmp_name'], "upload/" . $_FILES['file']['name']); echo "Stored in: " . "upload/" . $_FILES['file']['name']; } } } else { echo "Invalid file"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419570 Share on other sites More sharing options...
Kasak Posted December 20, 2007 Author Share Posted December 20, 2007 Stored in: upload/IMG_2981.jpg giving this if I see my link http://webstage.emich.edu/campuslife/Fall_07_Dev/webjobs/upload nothing is there Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419580 Share on other sites More sharing options...
~n[EO]n~ Posted December 20, 2007 Share Posted December 20, 2007 Check the permission for that Upload folder, is it set to chmod 777 (read / write access) and keep error_reporting(E_All); at top of your page Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419584 Share on other sites More sharing options...
Kasak Posted December 20, 2007 Author Share Posted December 20, 2007 my chmod is 1777 I did all the solutions suggest by other user in the forum but still not able to get the proper solution for this Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419589 Share on other sites More sharing options...
papaface Posted December 20, 2007 Share Posted December 20, 2007 Your chmod should be 0777 i think not 1777 ??? Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419590 Share on other sites More sharing options...
Kasak Posted December 20, 2007 Author Share Posted December 20, 2007 Warning: move_uploaded_file(upload/IMG_2999.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /data/personal/htdocs/ktahilra/upload_file.php on line 26 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/var/tmp/phpyDaGEb' to 'upload/IMG_2999.jpg' in /data/personal/htdocs/ktahilra/upload_file.php on line 26 Stored in: /upload/IMG_2999.jpg Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419598 Share on other sites More sharing options...
nitation Posted December 20, 2007 Share Posted December 20, 2007 I think your problem is from the set permissions. Try confirming your permissions and post what happens next. Quote Link to comment https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/#findComment-419819 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.