----- 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::-
>
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>
> <html>
> <head>
> <title>Uploader</title>
> </head>
> <body>
> <?php
>
> if(isset($_FILES['File'])) {
>
> $File=$_FILES['File'];
> $File_name=$_FILES['File']['name'];
> $File_size=$_FILES['File']['size'];
>
>
> echo ("<p>$File_name</p><br />\n");
> echo ($_FILES['File']['name']);
>
> print("File name: $File_name<p />\n");
> print("File size: $File_size<p />\n");
>
>
>
>
> if (copy ($_FILES["File"]["tmp_name"],"users/$File_name")) {
>    print("The file was sucessfully uploaded.<p />\n");
>    }else{
>    print("Your file could not be copied unfortunately.<p />\n");
>    }
>
>  unlink($File);
>  }
>
>  echo ("Upload a file to the server.");
>  echo ("<Form action=\"FileUpload.php\" method=POST
> enctype=\multipart/form-data\>\n");
>  echo ("File: <input type=file name=\"File\"><br />\n");
>  echo ("<input type=submit name=\"submit\" value=\"Press here to
> upload.\"><br /></ form>\n");
>
>
> //test whether anything prints for the FILES array
> echo ("<p><em><font color=\"green\">Can I get it to print the variable
> outside the conditional? i.e.  this one ----
> {$_FILES['File']['name']}.</font></em></p>\n");
>
>
>
> //set any old variable and print it to be sure basics work
> $TestPrint="<p><big><font color=\"purple\">Print this out
> then.</font></big></p>.\n";
>
> echo($TestPrint);
>
> ?>
> </body>
> </html>
>
>
> 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 "<br /></ form>\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

Reply via email to