Page 1 of 1
trying to copy an image file from a webserver to localserver
Posted: Fri Aug 28, 2009 5:10 am
by kalpeshpatel
i am using IIS server for running php .
i have one page where in i am trying to copy an image file from a webserver to my local server.
$image_path => local path
$image_url = "
http://www.xxx.com/dira/images/events.png";
copy($image_url,$image_path);
but I get an HTTP Bad Request error.
The same code works fine on UNIX environment. and also on windows working with WAMP server.
The allow_url_include option is also is kept ON.
please help me.
thank you
Re: trying to copy an image file from a webserver to localserver
Posted: Sun Aug 30, 2009 1:39 am
by kalpeshpatel
McInfo wrote:What is the exact error message?
If the copy() line is commented out, do you still get the error?
Is allow_url_fopen enabled in php.ini?
thx for reply me
but i got this error "failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request"
ya in php.ini allow_url_fopen = on
help me
Re: trying to copy an image file from a webserver to localserver
Posted: Sun Aug 30, 2009 11:58 pm
by kalpeshpatel
McInfo wrote:Help me help you. You answered two of my three questions.
What happens if you comment out the line that calls copy()? In other words, change the line to
If nothing changes, please post your script.
Can you access events.png directly through your browser without having to log in to the host site?
if i comment out the line that call copy(), so not get an error, its working fine.
yes i have access events.png directly through my browser without login.
but i want to copy this image to my local server.
thank you
Re: trying to copy an image file from a webserver to localserver
Posted: Mon Aug 31, 2009 12:54 pm
by superdezign
Maybe you could try making use of
cURL. I believe that in PHP5, they were moving away from cURL being a necessity in cross-server requests. However, it's still available for when you need it.
EDIT: Just noticed that McInfo has done that.
Re: trying to copy an image file from a webserver to localserver
Posted: Tue Sep 01, 2009 1:49 am
by kalpeshpatel
McInfo wrote:Try this. (Change $src to the remote file you are trying to copy.)
Code: Select all
<?php
header('Content-Type: text/plain');
$src = 'http://domain.tld/path/to/events.png'; // Change this
$dst = './events.png';
// See http://www.php.net/curl_setopt
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $src);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
file_put_contents($dst, $data);
echo 'Done.';
?>
thx for help
its work fine , not get any error but image copy only 2kb it means just create image file but not get image content.