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











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

Reply via email to