[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
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
[PHP] shorthand "if" notation
I am confused by the shorthand "if" notation. For example I just saw this PHP snippet on another forum I think it is an if but cannot find it in the manual. How is that written in the more normal notation - if(){} etc?? [And please excuse a slightly off-thread but related extension to the question but I have seen similar in Javascript - namely --- var evt = (evt ? evt : ((window.event) ? window.event : null); is this the same notation or something else?] Regards Adrian Greeman -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Editor
I am just surprised that noone mentioned HTML-Kit among all the editors suggested. I think it is fine and it even gives you a quick preview in browser window for HTML. It gives you PHP among various other options colouring the code differently and you can just highlight code to surround it with php tags for example. Does Java and other stuff too. Lots of plug-ins endlessly under development And it's FREE. I have it plugged in as the external text editor of choice with Dreamweaver. Regards Adrian Greeman Telephone +44 20 8672 9661 Mobile +44 780 329 7447 e-mail:- [EMAIL PROTECTED] or [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Register globals off
I am learning PHP with version 4.2. (Win ME, Apache, MySQL) on a PC I have to understand the new "register globals off" methods and it seems like a good idea to learn that from the beginning but all the books and beginners guides gives examples the old way. Would it be true to say that every time an example is given where data is passed on (for forms and so forth) that I can simply replace the variable in the example with $_POST or $_GET? Or do I have to do more? eg if a simple PHP file for handling form input takes in the data using $LastName can I simply use $_POST["LastName"]?? It seems to work for a very simple example. But should I read the array into a variable first? And do I need to do any validation or declaring of variables etc?? [I did have a problem reading in a number - the solution was to put (int) before the POST array name though I don't understand why that was not needed with a string. I am also unclear what happens when you send something using header() - does that also go into an array - if so which one and how do I use it? This may all seem unecessarily complicated but I am not yet au fait with the whole thing. Regards Adrian Greeman -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Can't get Apache and PHP to run together -each seems to work OK WinME
I am not an advanced user but not incapable. Please bear with me for any amateurishness. I am trying to get PHP to work with Apache. I have a Windows ME PC, 2Mhz and 512 of RAM. I want it only to learn PHP and then test out a few things, using MySQL too. I downloaded Apache version 1.3.24 and installed it plain and simple.It starts up. I have also installed PHP version 4.2.1. I have also a version of MySQL loaded (4.0.1) and that sits happily running under a WinMySQLAdmin logo in the corner of the screen. I carefully followed the help files and looked up articles and books for instructions for setting up the config file and have made changes to "Apache" so the relevant sections now read like this. (There seem only to be a few necessary changes)./ QUOTE ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache/cgi-bin/" # # "C:/Program Files/Apache Group/Apache/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # AllowOverride None Options None Order allow,deny Allow from all ScriptAlias /php/ "C:/PHP/" # End of aliases. END QUOTE and .. QUOTE # # AddType allows you to tweak mime.types without actually editing it, or to # make certain files to be certain types. # AddType application/x-tar .tgz AddType application/x-httpd-php .php AddType application/x-httpd-php .php3 AddType application/x-httpd-php .php4 AddType application/x-httpd-php .phtml Action application/x-httpd-php "/php/php.exe" END QUOTE With this done the Apache config tester says the syntax is OK and when I access "localhost" (using IE6) up comes the Apache information page saying it is running. But when I ask for "localhost/phpinfo.php" (I have a phpinfo function written into a file with that extension) I get an error 500 "internal configuration is wrong" message. Maybe it is PHP that is wrong?So I have checked all the changes needed for installing PHP --- again after reading the php site and looking a FAQs etc. I mean putting the php4tl file into Windows/System etc and PHP.ini into Windows. (I used the Windows installer anyway and have again carefully followed the changes needed to the INI file.) Still the problem. A PHP FAQ says that if you get a 500 error (internatl config problem) it is worth testing with the command line: php.exe -i so I did this in DOS. Reams of HTML stuff whizzed by. According to the FAQ answer this means PHP is OK. So back to Apache. But that is as above. I tried Netscape version 2 and IE6 - both give the same answer. So it is not the browser because I have tried different ones. It is not PHP because on the command line that works OK and shows PHPINFO stuff. It is not Apache because it says it is running in the browser windows when you call localhost. So - I am being driven slowly nuts with frustration. May I ask for any ideas? (I should add that I am a rank amateur trying to do all this so please take it slowly). Regards from Adrian Greeman Regards from Adrian Greeman 52 Salterford Road, Tooting, London, SW17 9TF Phone +44 (0)20 8672 9661 Mobile +44 (0)780 329 7447 Fax: I can receive these on the computer but only when present - please phone first -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php