-
Uploading problem
okay, so I'm trying to learn how to upload files but it isn't working.
upload.php
Code:
<HTML>
<HEAD>
<TITLE>Upload</TITLE>
</HEAD>
<BODY>
<FORM ACTION="xupload.php" METHOD="POST" ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="uploadfile"><BR><INPUT TYPE="submit" VALUE="Upload">
</FORM>
</BODY>
</HTML>
xupload.php
Code:
<?
echo "<PRE>";
echo "Local temp file called after upload: $uploadfile\n";
echo "original remote file called: $uploadfile_name\n";
echo "size of the file in bytes: $uploadfile_size\n";
echo "file type: $uploadfile_type\n";
echo "</PRE>";
echo "<HR>";
if ($uploadfile == "") {
#No file was uploaded
header("Location: upload.php");
exit;
}
?>
<HTML>
<BODY>
<?
if (copy($uploadfile,targetdir)) {
echo "File Uploaded OK";
#Delete Temp. File
unlink($uploadfile);
} else {
echo "File Upload Failed";
}
?>
<BR><BR>
<A HREF="upload.php">Continue</A>
</BODY>
</HTML>
-
Re: Uploading problem
Very likely, register_globals is switched off in your PHP. See here for more information:
http://www.php.net/manual/en/feature...ad.post-method
-
Re: Uploading problem
You should also use <?php ?> style tags rather that the generic ones. Again like register_globals, these are now turned off by default in PHP.
Rather than turning register globals on, you should use the $_POST, $_FILES and $_GET arrays. $_POST contains variables from posted forms and $_GET contains variables form the query string and $_FILES contains any uploaded files. You simply access them by their names:
PHP Code:
echo($_POST['varname']);
/* for a file */
echo "size of the file in bytes: $_FILES['uploadfile']['size']}\n";
See here for more info on uploading files.
-
Re: Uploading problem
Thank you both for your help!