檔名為
sendfile1.php <form name="form1"
method="post"
enctype="multipart/form-data"
action="sendfile2.php">
<p>Sender:<input type="text"
name="uname"></p>
<p>Select a file...</p>
<p><input type="file"
name="ufile"></p>
<p>
<input type="submit" name="Submit"
value="Send">
<input name="Reset" type="reset"
id="Reset" value="Reset">
</p>
</form>
|
檔名為 sendfile2.php <?php
$uname=$_POST["uname"];
$error_msg=$_FILES["ufile"]["error"];
$fname=$_FILES["ufile"]["name"];
$tmpname=$_FILES["ufile"]["tmp_name"];
$fsize=$_FILES["ufile"]["size"];
$ftype=$_FILES["ufile"]["type"];
echo "Hello, $uname <br>";
if($error_msg)
{
echo "<font color=red>Upload failed
!</font><p>";
echo "Error code : $error_msg ";
}
else
{
// upload successful
echo "Upload file name is $fname <br>";
echo "Upload file size is $fsize <br>";
echo "Upload file type is $ftype <br>";
echo "<hr>";
// save this file to a temp directory
$success=copy($tmpname,"temp/".$fname);
if($success)
{
echo "Save file is successful !<br>";
echo "Save as : temp/$fname<br>";
unlink($tmpname);
}
else
{
echo "<font color=red> Error to save this
file! </font>";
}
}
?>
|