{% else-1 %}
Скрипт передачи файлов методом POST предоставлен Арсеньевым Алексеем (больше известным на нашем форуме как JIEXA).

                        
function sendFile($host, $port="80", $path, $filePath, $fileName, $fileField, $fields = array())
{
define("CRLF", "rn");
define("DCRLF", CRLF.CRLF);

$boundary = "---------------------".substr(md5(rand(0,32000)),0,10);

$fieldsData = "";

if(count($fields) > "0"):
foreach($fields as $field => $value)
{
$fieldsData .= "--".$boundary.CRLF;
$fieldsData .= "Content-Disposition: form-data; name="".$field.""".DCRLF;
$fieldsData .= urlencode($value).CRLF;
}
endif;

$fileHeaders = "--".$boundary.CRLF;
$fileHeaders .= "Content-Disposition: form-data; name="".$fileField.""; filename="".$fileName.""".CRLF;
$fileHeaders .= "Content-Type: ".mime_content_type($filePath).DCRLF;
$fileHeadersTail = CRLF."--".$boundary."--".CRLF;

$filesize = filesize($filePath);
$contentLength = strlen($fieldsData) + strlen($fileHeaders) + $filesize + strlen($fileHeadersTail);

$headers = "POST $path HTTP/1.0".CRLF;
$headers .= "Host: ".$host.CRLF;
$headers .= "Referer: ".$host.CRLF;
$headers .= "Content-type: multipart/form-data, boundary=".$boundary.CRLF;
$headers .= "Content-length: ".$contentLength.DCRLF;
$headers .= $fieldsData;
$headers .= $fileHeaders;

if(!$fp = fsockopen($host, $port)) return false;
fputs($fp, $headers);

$fp2 = fopen($filePath, "rb");

while(!feof($fp2)) fputs($fp, fgets($fp2, 1024*100));

fclose($fp2);

fputs($fp, $fileHeadersTail);

$serverResponse = "";
while(!feof($fp)) $serverResponse .= fgets($fp, 4096);
fclose($fp);

return $serverResponse;
}
0 59 0
Без комментариев...