atrum Posted May 10, 2008 Share Posted May 10, 2008 Hello all, I am still new to php, and I am trying to get an file upload script to work. I am using the example found on w3schools.com, and everything appears to work on the front end, but when I browse to the upload directory on my server, I do not see the file that was just uploaded. I just need some help to try and figure out why. Here is the Html form. <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> And the php code <?php if ($_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("teamftp/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "teamftp/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> The output on the browser suggests that every thing works, but as I stated above, the file never gets loaded to the server. Also just some additional information on my server. I run apache 2.0 php 5.0 Freebsd 6.4 Directory to upload is chmoded to 777 for testing. any help you can give would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 10, 2008 Share Posted May 10, 2008 in move_uploaded_file(), try using a full path instead of a relative path here: "upload/" . $_FILES["file"]["name"] Quote Link to comment Share on other sites More sharing options...
atrum Posted May 10, 2008 Author Share Posted May 10, 2008 Thanks, I acutally figured out the real problem, and that was; the folder upload didn't exist because I was using another name, "teamftp" Now I seem to be running into another issue, and that is that any file I upload has no data. In other words, I uploaded a jpg image. That image is 200kb in size. On the server in the directory it uploaded to the file size shows 0kb. Any ideas on what would be causing that? Quote Link to comment Share on other sites More sharing options...
atrum Posted May 11, 2008 Author Share Posted May 11, 2008 bump Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 11, 2008 Share Posted May 11, 2008 i wouldn't expect it to matter, but you might need max_file_size in your form: <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> Quote Link to comment Share on other sites More sharing options...
atrum Posted May 12, 2008 Author Share Posted May 12, 2008 Ok I added the Max_file_size to my form, but that made no difference. The files are still being uploaded as 0kb files. Does any one have any ideas on this? 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.