Uploading
| From: | Patrick Dunford | Date: | Sat, 25 Nov 2000 10:35:46 +0000 |
| Subject: | Uploading | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-4100@lists.php.net to get a copy of this message | ||
I am using these two scripts that I downloaded from the internet to do a
file upload. I want the new filename to simply be the basename of the file
that the user browses to (so they don't have to enter a new filename).
However somewhere between the form submission and loading the second script
the filename gets changed to a temporary filename so I can't get the
original name from it. How do I pass the original name to the second script
from the first.
[Upload.php - gets loaded first]
<HTML>
<HEAD>
<TITLE>PHP - file upload</TITLE>
<style type="text/css">
<!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 10pt}
-->
</style>
</HEAD>
<BODY>
<center>
<table>
<FORM ENCTYPE="multipart/form-data" ACTION="upload_go.php" METHOD=POST>
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="100000">
<tr>
<td><b>file upload</b></td>
<td></td>
</tr>
<tr>
<td>file: </td>
<td><input type="File" name="userfile" size="30"
maxlength="255">
</td>
</tr>
<tr>
<td>target filename: </td>
<td><input type="Text" name="newname" size="30"
maxlength="^255">
</td>
</tr>
<tr>
<tr>
<td>Upload Directory: </td>
<td>/planner/</td>
</tr>
<td colspan="2" align="CENTER">
<INPUT TYPE="submit" VALUE="upload">
</td>
</tr>
</FORM>
</table>
</center>
</BODY>
</HTML>
[Upload_go.php]
<?php
function do_upload($filename,$newname) {
$file = basename($filename);
$tmp_upload_path = "/tmp/";
$new_file_name = "/home/pdunford/planner/".$newname;
if (!copy($tmp_upload_path.$file, $new_file_name)) echo "failed to copy
file<br>\n";
return;
}
?>
<HTML>
<HEAD>
<TITLE>PHP - file upload</TITLE>
<style type="text/css">
<!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 10pt}
-->
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF"
VLINK="#800080">
<?php
do_upload($userfile,$newname);
?>
<TABLE>
<TR>
<TD><b>Upload report</b></TD><TD></TD>
</TR>
<TR>
<TD>upload tmp file:</TD><TD><?php echo $userfile; ?></TD>
</TR>
<TR>
<TD>file name:</TD><TD><?php echo $userfile_name; ?></TD>
</TR>
<TR>
<TD>target file name:</TD><TD><?php echo $newname; ?></TD>
</TR>
<TR>
<TD>target directory:</TD><TD>/home/pdunford/planner/</TD>
</TR>
<TR>
<TD>file size:</TD><TD><?php echo $userfile_size; ?></TD>
</TR>
<TR>
<TD>file type:</TD><TD><?php echo $userfile_type; ?></TD>
</TR>
</TABLE>
</BODY>
</HTML>
=======================================================================
Patrick Dunford, Christchurch, NZ -
He was a good man, full of the Holy Spirit and faith, and a
great number of people were brought to the Lord.
-- Acts 11:24
http://www.heartlight.org/cgi-shl/todaysverse.cgi?day=20001124
=======================================================================
Created by Mail2Sig -