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
trying to copy an image file from a webserver to localserver
Moderator: General Moderators
-
kalpeshpatel
- Forum Newbie
- Posts: 5
- Joined: Sat Aug 22, 2009 12:24 am
-
kalpeshpatel
- Forum Newbie
- Posts: 5
- Joined: Sat Aug 22, 2009 12:24 am
Re: trying to copy an image file from a webserver to localserver
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
-
kalpeshpatel
- Forum Newbie
- Posts: 5
- Joined: Sat Aug 22, 2009 12:24 am
Re: trying to copy an image file from a webserver to localserver
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 toIf nothing changes, please post your script.Code: Select all
//copy($image_url,$image_path);
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
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: trying to copy an image file from a webserver to localserver
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.
EDIT: Just noticed that McInfo has done that.
-
kalpeshpatel
- Forum Newbie
- Posts: 5
- Joined: Sat Aug 22, 2009 12:24 am
Re: trying to copy an image file from a webserver to localserver
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.