Page 1 of 1
download image script
Posted: Fri Sep 17, 2004 7:56 pm
by jabbaonthedais
I'm trying to make just a few lined script where users put in a url of an image, and have it download it to their computer. I don't know if you can do this because of permissions. The purpose of this is to get around the IE bug that makes you download jpegs as a bmp.
I tried using variations of the below code, but I guess the copy command won't do it.
Code: Select all
<?php
$file = http://comedyhaven.com/CHLogo.jpg
$name = test1
copy($file, $name.'.bak');
?>
Posted: Fri Sep 17, 2004 8:08 pm
by feyd
that bug, is because the site doesn't send a content length header, from what I've seen.
Posted: Fri Sep 17, 2004 8:18 pm
by jabbaonthedais
There are several reasons this bug happens. But for many IE users, they cannot download any images (gif or jpeg) without saving them as a .bmp. Mozilla and other browsers do not have this problem.
Thats why I want to make a simple script, for me and my friends to use.
Posted: Fri Sep 17, 2004 9:01 pm
by feyd
use [php_man]file_get_contents[/php_man] to download the file, [php_man]fopen[/php_man] and it's siblings to create the file on the server.
Posted: Fri Sep 17, 2004 10:56 pm
by jabbaonthedais
I had to substitute file_get_contents for file because my php version is older.
Code: Select all
<?php
$url = 'http://comedyhaven.com/CHLogo.jpg';
list($protocol, $uri) = split('//', $url);
$html = file($url);
fopen("file.jpg", "wb");
?>
When I use this code, it creates the file on my server, but it's 0 bytes. It's not downloading it properlly.
Posted: Fri Sep 17, 2004 11:10 pm
by feyd
your code doesn't write anything to the file.