Downloading MP4 files with PHP CURL -


i trying download video 1 of servers of servers. using curl because copy() did not download audio video. however, curl downloaded corrupted files (?) , not. how i'm downloading mp4 file right now:

$source = "https://link.com/video.mp4"; $ch = curl_init(); curl_setopt($ch, curlopt_url, $source); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_sslversion,3); $data = curl_exec ($ch); $error = curl_error($ch); curl_close ($ch);  $destination = "video/video.mp4"; $file = fopen($destination, "wb"); fwrite($file, $data); fclose($file); 

is there special mp4 files download properly?

array(26) { ["url"]=> string(60) "https://link.com/video.mp4" ["content_type"]=> null ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(1) ["redirect_count"]=> int(0) ["total_time"]=> float(0.135745) ["namelookup_time"]=> float(8.4e-5) ["connect_time"]=> float(0.056009) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(13) "an-ip :d" ["certinfo"]=> array(0) { } ["primary_port"]=> int(443) ["local_ip"]=> string(11) "192.168.0.9" ["local_port"]=> int(57478) }

you must open file in binary mode ensure file saved disk correctly.

$file = fopen($destination, "wb"); 

also use fwrite instead of fputs

fwrite($file, $data); 

check video.mp4 downloads browser correctly. maybe redirecting? if add option.

curl_setopt($ch, curlopt_followlocation, 1); 

if still not work dump out info , post it.

var_dump(curl_getinfo($ch)); 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -