El codigo funciona con archivo menor a 2 mb, el problema es que los archivos pueden llegar a pesar 150 mb.
Código PHP:
function send_zip_course($url, $_data, $pathFile) {
$url = parse_url($url);
if ($url['scheme'] != 'http') {
die('Only HTTP request are supported !');
}
$host = $url['host'];
$path = $url['path'];
srand((double)microtime()*1000000);
$boundary = "---------------------".substr(md5(rand(0,32000)),0,10);
// Build the header
$header = "POST $path HTTP/1.0\r\n";
$header .= "Host: $host\r\n";
$header .= "Content-type: multipart/form-data, boundary=$boundary\r\n";
$data = '';
foreach($_data AS $index => $value){
$data .="--$boundary\r\n";
$data .= "Content-Disposition: form-data; name=\"".$index."\"\r\n";
$data .= "\r\n".$value."\r\n";
$data .="--$boundary\r\n";
}
// and attach the file
$data .= "--$boundary\r\n";
$content_file = file_get_contents($pathFile);
$data_file .= "Content-Disposition: form-data; name=\"userfile\"; filename=\"".$pathFile."\"\r\n";
$data_file .= "Content-Type: application/zip \r\n\r\n";
$data_file .= "".$content_file."\r\n";
$data_file .= "--$boundary--\r\n";
$header.= "Content-length: " . (strlen($data)+ strlen($data)+ strlen($data_file)). "\r\n\r\n";
// Open the connection
$fp = fsockopen($host, 80);
$result = '';
// Send header
fwrite($fp, $header);
fwrite($fp, $data);
// Send content
self::fwrite_with_retry($fp, $data_file);
fclose($fp);
}
function fwrite_with_retry($sock, &$data)
{
$bytes_to_write = strlen($data);
$bytes_written = 0;
while ( $bytes_written < $bytes_to_write )
{
if ( $bytes_written == 0 ) {
$rv = fwrite($sock, $data);
} else {
$rv = fwrite($sock, substr($data, $bytes_written));
}
if ( $rv === false || $rv == 0 )
return( $bytes_written == 0 ? false : $bytes_written );
$bytes_written += $rv;
}
return $bytes_written;
}
Código PHP:
...
move_uploaded_file($_FILES['userfile']['tmp_name'], $path_couse.DS.$file_name);
...
Código PHP:
ini_set('post_max_size','200M');
ini_set('upload_max_filesize','200M');
ini_set('memory_limit','256M');
ini_set('max_execution_time',1800);