File Uploads / FORM
| From: | Daniel Reichenbach | Date: | Wed, 17 Oct 2001 12:55:28 +0000 |
| Subject: | File Uploads / FORM | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-71332@lists.php.net to get a copy of this message | ||
Hy PHP users,
In the php manual i found a method to simulate file uploads with forms
using PHP in an annotation.
( http://www.php.net/manual/en/features.file-upload.php
)
Well.. Tried this script and sent it to my upload handler. What happens?
PHP doesn't get the uploaded file.
Attached are the scripts. Can anyone help me?
Daniel
--- doupload.php / HTTP POST ---
<?
//To upload a file manually using fsockopen :
// the receiver of file
$remote_page = "http://localhost/upload/upload.php";
// the file you want to upload
$file = "c:\\opensa\\apache\\readme.txt"; // the file location
$con_type = "text/plain"; // the file mime type
//$file = "c:\\temp\\view3.jpg"; // the file location
//$con_type = "image/jpg"; // the file mime type
$content_file = join("",file($file));
// define boundary
srand((double)microtime()*1000000);
$boundary =
"---------------------------".substr(md5(rand(0,32000)),0,10);
$data = "--$boundary
Content-Disposition: form-data; name=\"file\"; filename=\"$file\"
Content-Type: $con_type
$content_file"."--$boundary--\r\n\r\n";
$msg =
"POST $remote_page HTTP/1.0
Content-Type: multipart/form-data; boundary=$boundary
Content-Length: ".strlen($data)."\r\n\r\n";
//echo "<pre>".$msg.$data."</pre>";
$f = fsockopen("localhost",80);
fputs($f,$msg.$data);
$result = fread($f,32000);
fclose($f);
//print $result."\n<br>";
?>
--- upload.php / POST handler ---
<?php
if (is_uploaded_file($userfile)) {
echo $userfile;
copy($userfile,
"c:\\opensa\\apache\\htdocs\\upload\\".$userfile_name);
} else {
echo "Possible file upload attack: filename '$userfile'."; }
?>