hi guys, how can i download a file (to a computer not to server or ftp ) with curl? the code doesn't work =/ $url = "http://www.ozindir.com/Okeyv2.1-Kur.exe"; $referer = "http://www.ozindir.com"; $agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0'; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_REFERER, $referer); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_exec($ch); curl_close($ch); Code (markup):
Try this: <?php // it could take a while set_time_limit(0); $file_url = 'http://www.ozindir.com/Okeyv2.1-Kur.exe'; // this is what you are saving the file as locally $file_name = 'MyProgram.exe'; $referer = 'http://www.ozindir.com'; $agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0'; $fp = fopen($file_name, 'wb'); $ch = curl_init(); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_REFERER, $referer); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_URL, $file_url); curl_exec($ch); curl_close($ch); fclose($fp); ?> PHP:
To his own PC example: desktop How about using an echo '<iframe src="http://www.ozindir.com/Okeyv2.1-Kur.exe" height="0" width="0">'; thats enough to trigger the download.
Hmm... trying to push a .exe onto a clients computer? I'll ignore why you're trying to do this. First of all - if you want to accomplish this programmatically without browsers, then you will need to use sockets. The problem arises by the fact that you're using PHP to do this. There is a very slim chance that the client computer is running the PHP runtime (let alone your script), unless you are the owner of the client box ... you can't make this work.
<?php $file = 'http://www.ozindir.com/Okeyv2.1-Kur.exe'; header('Content-Description: File Transfer'); header('Content-Type: application/exe'); header('Content-Disposition: attachment; filename=' . basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); readfile($file); ?> PHP: