note 9797 added to Handling file uploads

From: Date: Fri, 24 Nov 2000 09:14:33 +0000
Subject: note 9797 added to Handling file uploads
Groups: php.notes 
Request: Send a blank email to php-notes+get-8101@lists.php.net to get a copy of this message
Hi, this is to upload a file manually ... For example you want to upload /home/alexander/myfile.gif to http://127.0.0.1/upload.php : <? srand((double)microtime()*1000000); $file = "/home/alexander/myfile.gif"; $content_type = "image/gif"; $content_file = join("",file($file)); $remote_page = "http://127.0.0.1/upload.php"; $boundary = "---------------------------".substr(md5(rand(0,32000)),0,10); $data = "--$boundary Content-Disposition: form-data; name=\"file\"; filename=\"$file\" Content-Type: $content_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"; $result=""; $f = fsockopen("127.0.0.1",80); fputs($f,$msg.$data); while (!feof($f) $result .= fread($f,32000); fclose($f); print $result; ?> LexZEUS http://www.php.net/manual/features.file-upload.php

« previous php.notes (#8101) next »