...

View Full Version : Upload script



fikka
02-15-2006, 02:15 PM
I need to upload text file from the local machine to the server. The problem is I'm getting only file name, but not the contents. Here is my script:



printf("<TABLE>\n");

printf(" <TD NOWRAP>\n");


printf(" <FORM NAME=\"UplForm\" METHOD=\"POST\" ENCTYPE=\"multipart/form-data\" ACTION=\"upload.php\" AUTOCOMPLETE=off>\n");

printf(" <TD>\n");
printf(" File to upload:\n");
printf(" </TD>\n");
printf(" <TD>\n");

printf(" <INPUT TYPE=file ACCEPT=\"text/plain\" NAME=\"upfile\" SIZE=\"40\" VALUE=\"Browse\">\n");


printf(" </TD>\n");
printf("</TABLE>\n");
printf(" <INPUT TYPE=submit VALUE=\"Upload file:\">\n");

printf(" </FORM>\n");


And all I get in the upload.php script is $upfile = “filename.txt”.
All functions like filesize, file_exists return nothing.

What I'm doing wrong?

ralph l mayo
02-15-2006, 10:32 PM
Wrapping all that stuff in printf is a waste of resources and your HTML is kind of a mess, but the PHP part looks ok.

Eg., I changed this to post to itself and added the little snip at the end:


<FORM NAME="UplForm" METHOD="POST" ENCTYPE="multipart/form-data" ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" AUTOCOMPLETE=off>
<TABLE>
<TD>
File to upload:
</TD>
<TD>
<INPUT TYPE=file ACCEPT="text/plain" NAME="upfile" SIZE="40" VALUE="Browse">
</TD>
</TABLE>
<INPUT TYPE=submit VALUE="Upload file:">
</FORM>
<?php
if (isset($_FILES['upfile']))
{
print_r($_FILES['upfile']);
}
?>


and I get:


Array
(
[name] => some.file // the name of the file on the uploader's computer
[type] => application/octet-stream
[tmp_name] => /tmp/php2A8.tmp // the actual file name on disc until you use move_uploaded_file() on it
[error] => 0
[size] => 455
)

fikka
02-16-2006, 04:21 PM
Wrapping all that stuff in printf is a waste of resources and your HTML is kind of a mess, but the PHP part looks ok.

Eg., I changed this to post to itself and added the little snip at the end:


<FORM NAME="UplForm" METHOD="POST" ENCTYPE="multipart/form-data" ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" AUTOCOMPLETE=off>
<TABLE>
<TD>
File to upload:
</TD>
<TD>
<INPUT TYPE=file ACCEPT="text/plain" NAME="upfile" SIZE="40" http://www.codingforums.com/newreply.php?do=newreply&p=410339VALUE="Browse">
</TD>
</TABLE>
<INPUT TYPE=submit VALUE="Upload file:">
</FORM>
<?php
if (isset($_FILES['upfile']))
{
print_r($_FILES['upfile']);
}
?>


and I get:


Array
(
[name] => some.file // the name of the file on the uploader's computer
[type] => application/octet-stream
[tmp_name] => /tmp/php2A8.tmp // the actual file name on disc until you use move_uploaded_file() on it
[error] => 0
[size] => 455
)


Big thnx!

dniwebdesign
03-02-2006, 08:57 AM
Edit.... Sorry... replyed when I wanted a new one... <_<



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum