aebstract Posted March 12, 2007 Share Posted March 12, 2007 Hello, I am trying to write a simple upload script, I will be making it a lot more involved later on, for now I just want it to work. The php code seems to cause nothing on the page to display: upload.php <?php ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset ($_POST['submit'])) { if (move_uploaded_file ($FILES['thefile']['tmp_name'], "../uploads/$_FILES['thefile']['name']}")) { print 'Your file has been uploaded.'; } else { switch ($_FILES['thefile']['error']) { case 1: print 'The file exceeds the upload_max_filesize setting in php.ini'; break; case 2: print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form'; break; case 3: print 'The file was only partially uploaded'; break; case 4: print 'No file was uploaded'; break; } } } ?> www.hillmarketinggroup.com/upload.php If anyone can tell me what is wrong/causing this that would be great. Also, I am not sure if this does it or not, but I will be wanting to change the filename when it is uploaded. That is possible, right? Thanks! Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted March 12, 2007 Share Posted March 12, 2007 The page is blank. What is your problem? BTW try: <?php print_r( $_POST ); print_r( $_FILES ); ?> monk.e.boy Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 12, 2007 Author Share Posted March 12, 2007 Uhg sorry, I thought I posted the entire code for the page, and I just put up the php: This is what I have.. upload.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>upload mailers</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset ($_POST['submit'])) { if (move_uploaded_file ($FILES['thefile']['tmp_name'], "../uploads/$_FILES['thefile']['name']}")) { print 'Your file has been uploaded.'; } else { switch ($_FILES['thefile']['error']) { case 1: print 'The file exceeds the upload_max_filesize setting in php.ini'; break; case 2: print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form'; break; case 3: print 'The file was only partially uploaded'; break; case 4: print 'No file was uploaded'; break; } } } ?> <form action="upload.php" enctype="multipart/form-data" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <input type="file" name="thefile" /> <input type="submit" value="upload" /> </form> </body> </html> The page being blank IS the problem. The form isn't showing up? Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted March 12, 2007 Share Posted March 12, 2007 try uploading it again. I assume other php files work for you, so it may be a broken FTP transfer? Then try deleting all the PHP and see if that works. monk.e.boy Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 12, 2007 Author Share Posted March 12, 2007 I did try uploaded several times, php does work on the server. I have tryed removing all the php and the form did display, that is why I came here for help. Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted March 12, 2007 Share Posted March 12, 2007 This line has a } in it. <?php if (move_uploaded_file ($FILES['thefile']['tmp_name'], "../uploads/$_FILES['thefile']['name']}")) { ?> Try commenting out all the lines of PHP and add them back in one at a time. monk.e.boy Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 12, 2007 Author Share Posted March 12, 2007 Okay that was the problem, thanks for spotting that. Moving along: I took out the ../ and made a folder called uploads in the same directory that that file is located. I tryed the form, nothing is happening (the error messages aren't saying that it uploaded or errored and nothing is being uploaded) Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted March 12, 2007 Share Posted March 12, 2007 looks like the move_uploaded_file function spuds out your PHP session. Try using full paths: /usr/blah/file.png monk.e.boy Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 12, 2007 Author Share Posted March 12, 2007 Sorry, I have never done anything with uploading so it is all new to me. What part should I change out? Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted March 12, 2007 Share Posted March 12, 2007 <?php if (move_uploaded_file ($FILES['thefile']['tmp_name'], "/my/path/$_FILES['thefile']['name']")) { ?> monk.e.boy Quote Link to comment Share on other sites More sharing options...
papaface Posted March 12, 2007 Share Posted March 12, 2007 Make sure the permissions for the folder you are trying to move the file to are correct. Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 12, 2007 Author Share Posted March 12, 2007 Permissions are set to 777, the folder is uploads which is located in the main directory, same directory as the upload.php file. 1 files and directories in hillmarketinggroup.com / httpdocs / uploads total Thats the uploads folder found in the directory and upload.php is in httpdocs. With all of that said, how is this line wrong? if (move_uploaded_file ($FILES['thefile']['tmp_name'], "uploads/{$_FILES['thefile']['name']}")) { I want it in the uploads folder, what would I put in front of uploads, if its in the main dir? Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted March 12, 2007 Share Posted March 12, 2007 try putting the complete path from '/' to your directory. If this works, then PHP is not finding the uploads dir. monk.e.boy Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 12, 2007 Author Share Posted March 12, 2007 Okay I tryed: if (move_uploaded_file ($FILES['thefile']['tmp_name'], "/httpdocs/uploads/{$_FILES['thefile']['name']}")) { and if (move_uploaded_file ($FILES['thefile']['tmp_name'], "hillmarketinggroup.com/httpdocs/uploads/{$_FILES['thefile']['name']}")) { and if (move_uploaded_file ($FILES['thefile']['tmp_name'], "hillmarketinggroup.com/uploads/{$_FILES['thefile']['name']}")) { none are doing anything, just basically brings me back to the form. What I don't get is why it isn't telling me the reason it isn't uploading. Is there any code I can add on to that line to see if there are any errors coming out of it? Quote Link to comment Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 Please go and check your php.ini. check post_max_size upload_max_filesize if the file you upload is exceed upload_max_filesize or post_max_size, then upload process will be terminate automatically. and <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> should be removed from your upload page, if you have read through upload file section, you will know that php don't recognize MAX_FILE_SIZE during upload process (strange thing is the example in www.php.net use this hidden input box ??!! ). Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 12, 2007 Author Share Posted March 12, 2007 Well I was using the PHP for the world wide web book to make the form, theres a section on it. I went through and checked all that with my php.ini, which can be found at: www.hillmarketinggroup.com/phpinfo.php also they say to use the hidden field for some reason. Even if my file size I am trying to upload is too big, wouldn't the error message display?? Quote Link to comment Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 I can tell you that you cannot control client site. Try not to believe all the data come from browser. ya, they also told me to use the hidden field for some reason, after that I had spent two days three nights to solve this problem, finally I come out with not to use this hidden field. Maybe your book is good, but not always right. The error message display, sometimes don't work on php, maybe bugs,settings, error msg disable blah blah blah..... Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 12, 2007 Author Share Posted March 12, 2007 okay I took the hidden field out and still tryed, yet there is still nothing going on at all. Quote Link to comment Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 move_uploaded_file ($FILES['thefile']['tmp_name'], "../uploads/$_FILES['thefile']['name']}")) I see. In sentence above what is $FILES ? It should be $_FILES. I have tested the code I wrote just now. It should work for you also. Save it to test.php, then run it and see how.... [ <?php print_r($_FILES); if (move_uploaded_file($_FILES['thefile']['tmp_name'], "../uploads/".$_FILES['thefile']['name'])) { } else{ echo "Error"; } ?> <form action="test.php" enctype="multipart/form-data" method="post" > <input type="file" name="thefile" /> <input type="submit" value="upload" /> </form> ] Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 12, 2007 Author Share Posted March 12, 2007 Array ( [thefile] => Array ( [name] => civic.jpg [type] => image/jpeg [tmp_name] => /tmp/php15QnkE [error] => 0 => 102006 ) ) Error Thats what happens when I try and submit something through it? Quote Link to comment Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 rt. maybe the "../uploads/".$_FILES['thefile']['name'], path and file name is not correct, it just a small matter. Well done. Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 12, 2007 Author Share Posted March 12, 2007 well done? It isnt uploading files to "uploads" folder yet, so its not fixed? I dont think >.< Quote Link to comment Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 sorry. One's home work should be done by oneself. Moving the file from /tmp/php15QnkE to /uploads/$_FILES['thefile']['name'] folder doesn't seems too challenging to you. I know you can do it by yourself. hei,hei. why don't you hard code your path and filename for testing (using absolute path)? Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 12, 2007 Author Share Posted March 12, 2007 Maybe cause I have no clue what you're even talking about and if I came to forums to get help, I don't expect to be told to go figure it out on my own. I figure help forums would help me get the problems fixed, not leave me with them basically where I started at... Quote Link to comment Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 I don't know what are you thinking, but have you ever try to finish it by yourself ? Or you just want me to finish it ? ? Sorry for that, I can't do it. 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.