xampp - download file with php -
i wondering. have 2 computers 1 installed xampp , other 1 not.(same network). both windows xp
and making script test download file.
<?php $txt = "http://www.branded3.com/wp-content/uploads/2011/05/google_chrome1.jpg"; $img = "01.jpg"; file_put_contents($img, file_get_contents($txt)); ?> and run script on computer xampp installed, , absolutely works.
but running on computer, not working. can me in issue?
heres crude way can proxy image , prompt download.
<?php $url = "http://www.branded3.com/wp-content/uploads/2011/05/google_chrome1.jpg"; //get file $source = file_get_contents($url); //image mime types $images = array('jpg'=>'image/jpg','png'=>'image/png','png'=>'image/png'); //is image extention if(in_array(substr($url,-3),$images)){ $type = $images[substr($url,-3)]; }else{ //no somthing else $type = 'application/octet-stream'; } //set headers header('content-description: file transfer'); header('content-type: '.$type); header('content-disposition: attachment; filename='.basename($url)); header('content-transfer-encoding: binary'); header('content-length: ' . sprintf("%u", strlen($source))); header('cache-control: must-revalidate, post-check=0, pre-check=0'); header('expires: 0'); header('pragma: public'); //echo source echo $source; ?>
Comments
Post a Comment