file upload
| From: | anders thoresson | Date: | Wed, 02 Apr 2003 12:17:16 +0000 |
| Subject: | file upload | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-141970@lists.php.net to get a copy of this message | ||
Am I making any obvious mistakes here, in my upload script? I want to upload text-files only, they should end up in the directory from which the script is executed and be names __traningsmatcher.txt.
HTML-form:
<FORM ENCTYPE="multipart/form-data" METHOD=POST ACTION="store.php">
<TABLE>
<INPUT NAME="max_file_size" TYPE="hidden" VALUE="3000000">
<TR>
<TD>Fil: </TD>
<TD><INPUT NAME="userfile" TYPE="file"></TD>
</TR>
<TR>
<TD></TD>
<TD><INPUT TYPE=submit VALUE=" skicka "></TD>
</TR>
</TABLE>
</FORM>
And php, on the recieving end:
<?php
// check and validate uploaded file
if($_FILES['userfile'] == "none") {
die("Problem: Ingen fil uppladdad.");
}
if($_FILES['userfile']['size'] == 0) {
die("Problem: Filen är tom.");
}
if($_FILES['userfile']['type'] != "text/plain") {
die("Problem: Filen är inte en textfil.");
}
if(!is_uploaded_file($_FILES['userfile']['tmp_name'])) {
die("Problem: Filen är inte uppladdad");
}
$upfile = "__traningsmatcher.txt";
if(!copy($_FILES['userfile']['tmp_name'], $upfile)) {
die("Kunde inte spara filen");
}
echo("Filen är sparad!");
?>
--
anders thoresson