Re: [PHP] Files uploads problem
Thank you very much - you are very observant and have just taught me a good lesson about checking minor errors even outside the obvious PHP code. It works now except for the unlink as you said. Regards Adrian Greeman Original Message - From: "Kevin Stone" <[EMAIL PROTECTED]> To: "Adrian Greeman" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Monday, March 31, 2003 11:37 PM Subject: Re: [PHP] Files uploads problem > > - Original Message - > From: "Adrian Greeman" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Monday, March 31, 2003 3:04 PM > Subject: [PHP] Files uploads problem > > > > > > But I am having real trouble making a file upload programme work. It needs > > substitution of $FileName given in the example with $_FILES array values > > which I have done and use of isset instead of a raw if(). But I still > > cannot get it to work > > > > May I put the code here and ask if anyone can tell me the problem. ..> > > Couple of HTML problems to point out. Where you have "\n", form> is an invalid tag. Remove the space. Also where you have > "enctype=\multipart/form-data\>" you need quotes after the slashes (ie. \") > otherwise PHP is going to assume that you want the litteral slash in the > HTML. > > Niether of these errors will return visable error code but both will result > in you not being able to submit the form. > > Also when you go to unlink($File); you're going to see an error becuase > $File is not a valid file path, it's an array. Besides you shouldn't worry > about trying to clean up the temp file. PHP will do it automatically when > the script exists. :-) > > HTH, > Kevin > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Files uploads problem
- Original Message - From: "Adrian Greeman" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, March 31, 2003 3:04 PM Subject: [PHP] Files uploads problem > I am a learner in PHP - I have been using Larry Ullman's Peachpit beginners > book which I have found useful to take me through the basics. > > But the examples were written before the general applicaton of the new > $_POST, $_GET and similar arrays. It has been valuable learning to change > the code for that (I use version 4.2. (and a bit) and Larry Ullman is very > helpful on his own website forum with readers' queries on the book examples. > > But I am having real trouble making a file upload programme work. It needs > substitution of $FileName given in the example with $_FILES array values > which I have done and use of isset instead of a raw if(). But I still > cannot get it to work > > May I put the code here and ask if anyone can tell me the problme. > Incidentally I use Windows ME with Apache 2.0.36 and PHP 4.2.. The files > upload is on with a max size of 2M and no specific directory given for a > temp store (the INI says it will use the default directory.) > > My test out script is as follows::- > > > > > > > Uploader > > > > if(isset($_FILES['File'])) { > > $File=$_FILES['File']; > $File_name=$_FILES['File']['name']; > $File_size=$_FILES['File']['size']; > > > echo ("$File_name\n"); > echo ($_FILES['File']['name']); > > print("File name: $File_name\n"); > print("File size: $File_size\n"); > > > > > if (copy ($_FILES["File"]["tmp_name"],"users/$File_name")) { >print("The file was sucessfully uploaded.\n"); >}else{ >print("Your file could not be copied unfortunately.\n"); >} > > unlink($File); > } > > echo ("Upload a file to the server."); > echo (" enctype=\multipart/form-data\>\n"); > echo ("File: \n"); > echo (" upload.\">\n"); > > > //test whether anything prints for the FILES array > echo ("Can I get it to print the variable > outside the conditional? i.e. this one > {$_FILES['File']['name']}.\n"); > > > > //set any old variable and print it to be sure basics work > $TestPrint="Print this out > then..\n"; > > echo($TestPrint); > > ?> > > > > > Is there something I've missed in the script. Or perhaps Apache 2 is the > problem? > Thanks Couple of HTML problems to point out. Where you have "\n", is an invalid tag. Remove the space. Also where you have "enctype=\multipart/form-data\>" you need quotes after the slashes (ie. \") otherwise PHP is going to assume that you want the litteral slash in the HTML. Niether of these errors will return visable error code but both will result in you not being able to submit the form. Also when you go to unlink($File); you're going to see an error becuase $File is not a valid file path, it's an array. Besides you shouldn't worry about trying to clean up the temp file. PHP will do it automatically when the script exists. :-) HTH, Kevin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Files uploads problem
I am a learner in PHP - I have been using Larry Ullman's Peachpit beginners book which I have found useful to take me through the basics. But the examples were written before the general applicaton of the new $_POST, $_GET and similar arrays. It has been valuable learning to change the code for that (I use version 4.2. (and a bit) and Larry Ullman is very helpful on his own website forum with readers' queries on the book examples. But I am having real trouble making a file upload programme work. It needs substitution of $FileName given in the example with $_FILES array values which I have done and use of isset instead of a raw if(). But I still cannot get it to work May I put the code here and ask if anyone can tell me the problme. Incidentally I use Windows ME with Apache 2.0.36 and PHP 4.2.. The files upload is on with a max size of 2M and no specific directory given for a temp store (the INI says it will use the default directory.) My test out script is as follows::- Uploader $File_name\n"); echo ($_FILES['File']['name']); print("File name: $File_name\n"); print("File size: $File_size\n"); if (copy ($_FILES["File"]["tmp_name"],"users/$File_name")) { print("The file was sucessfully uploaded.\n"); }else{ print("Your file could not be copied unfortunately.\n"); } unlink($File); } echo ("Upload a file to the server."); echo ("\n"); echo ("File: \n"); echo ("\n"); //test whether anything prints for the FILES array echo ("Can I get it to print the variable outside the conditional? i.e. this one {$_FILES['File']['name']}.\n"); //set any old variable and print it to be sure basics work $TestPrint="Print this out then..\n"; echo($TestPrint); ?> Is there something I've missed in the script. Or perhaps Apache 2 is the problem? Thanks Regards Adrian Greeman Telephone +44 20 8672 9661 Mobile +44 780 329 7447 E-mail adresses [EMAIL PROTECTED] or [EMAIL PROTECTED] **Please note - there is a 400kB filter on my e-mail so if you send a large item (eg a JPEG pic) please also send a separate smaller message to tell me the other one is coming. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php