Hi, Basicly what I need says in the title: I NEED TO DOWNLOAD IMAGE FROM WEB TO SERVER USING PHP, is that possible ? if yes, does anyone has simple example of the code which can do that ?
I check it out those , but I cant find any samples over there that would download image and save it to disk, just some examples of getting .html documents
Something like this should work. <?php $filelocation = "http://www.site.com/folder/image.gif"; $foldertosave = "./images/"; $open = fopen($filelocation, "rb"); $contents = stream_get_contents($open); fclose($open); $save = fopen(array_pop(split("/", $filelocation)), "a"); fwrite($save,$contents); fclose($save); ?> PHP: You'll probably want to do some verification to make sure that the file being uploaded is in fact an image. The best way I can think of doing that is to open the image using the GD library and if it returns an error, the file is not an image.
<?php $filename=$_REQUEST['filename']; $filename = realpath($filename); $file_extension = strtolower(substr(strrchr($filename,"."),1)); /****Set Header Content Type based on File Extension****/ switch ($file_extension) { case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpe": case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } if (!file_exists($filename)) { die("NO FILE HERE"); } header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: $ctype"); header('Content-Description: File Transfer'); header("Content-Disposition: attachment; filename=\"".basename($filename)."\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); set_time_limit(0); @readfile("$filename") or die("File not found."); ?>