I need to make a php page which posts files and other variables to another php page, i found and tryed the following script but it doesn't work, if I read the posted filesize I get 0
Can you help me with this script? welcome are other solutions also
<?php
// function to read server name
function servername($txt)
{
if (substr(strtoupper($txt),0,4)=="WWW.")
$txt="HTTP://".$txt;
if (substr(strtoupper($txt),0,7)!="HTTP://")
return 0;
eregi("([url]http://([/url][/ ]+))",$txt,$arr);
return $arr[2];
}
// init ...
srand((double)microtime()*1000000);
$file = "test2.dat";
$remote_page = "http://mysite/savefile.php";
$boundary = "---------------------------".substr(md5(rand(0,32000)),0,10);
// read the file
$fp = @fopen($file,"r");
if (!$fp) die ("Cannot read $file !!");
$content_file = fread($fp,filesize($file));
fclose($fp);
// define HTTP POST DATA
$data = "--$boundary\r\n".
"Content-Disposition: form-data; name=\"file\"; filename=\"$file\"\r\n".
"Content-Type: application/octet-stream\n\n$content_file".
"--$boundary--\r\n\r\n";
$msg = "POST $remote_page HTTP/1.0\r\n".
"Content-Type: multipart/form-data; boundary=$boundary\r\n".
"Content-Length: ".strlen($data)."\r\n\r\n";
// Open socket connection ...
$f = fsockopen(servername($remote_page),80);
if ($f)
{
// Send the data
fputs($f,$msg.$data);
// retrieve the response
$result="";
while (!feof($f)) $result.=fread($f,1024);
fclose($f);
// write the response (if needed)
print $result;
}
else
die ("Cannot connect !!!");
?>
The page that receive the post (savefile.php)
<?
echo "->".$FILES['file']['name']."<br>";
echo "->".$FILES['file']['size'];
die;
$filename = $FILES['file']['name'];
$storage_folder = $SERVER['DOCUMENT_ROOT']."/storage/13/";
echo $storage_folder. $filename;
if (!copy($_FILES['file']['tmp_name'], $storage_folder. $filename)) $err_desc="Problemi durante il salvataggio del file";
?>
Thanks