473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Converting fopen to cURL

I'm getting some warning using the code below:
Error:
Expand|Select|Wrap|Line Numbers
  1. failed to open stream: Permission denied in
Code:
[PHP]
function wwwcopy($url,$dirname){
$file = fopen($url, "r");
if (!$file) {
echo"<font color=red>Failed to copy $url!</font><br>";
return false;
}else {
$fc = fopen("$dirname", "w");
while (!feof ($file)) {
$line = fread ($file, 1028);
fwrite($fc,$line);
}
fclose($fc);
echo "<font color=blue>File $url saved to PC!</font><br>";
return true;
}
}
[/PHP]

I have checked my php.ini settings and my folder/file permissions seem to be set right so i dont know if my host is restricting me or whats up.
Expand|Select|Wrap|Line Numbers
  1. allow_url_fopen = On
If someone can help me getting through that issue i wont have to convert to cURL.

*NOTE files hosted on the same server I can copy just not stuff on other servers and thats what i want this code for. This code is meant to copy IMAGES.

But I have also started the cURL code but can't seem to get it working, all i get is a file that contains text! ex. http://someothersite.com/images/image.gif i dont really no anything about cURL and i'm a total noob at php so any help would be appreciated.

[PHP]function wwwcopy($address,$dirname){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $address);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
$FileName = $dirname;
$fh = fopen($FileName, 'w') or die("can't open file");
fwrite($fh, $data);
fclose($fh);}[/PHP]
Nov 1 '07 #1
1 4662
C'mon i know this isn't that hard, at least provide me with some working cURL code cause i really need this.

Thank you in advance.
Nov 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Grant | last post by:
Hi, I'm trying to use fopen to open a remote page. I found a page that doesn't work, and it's because the page requires cookies. Is there a way in PHP to pass cookies to a remote host? Here...
3
by: James | last post by:
Hi guys, I have been building a search engine here - not because I have plans of dethrowning Google but as a simple app upon which to develop a function set that I can use for other things. ...
11
by: typingcat | last post by:
Is it possible to read another web page in PHP? If is ASP.NET, the code would be ------------ WebRequest req=WebRequest.Create("http://www.microsoft.com"); WebResponse res=req.GetResponse();...
4
by: lucyachammond | last post by:
I have a 3rd party real-estate website written in php. I would like to call an asp script on a separate webserver each time a new real-estate item is added to the database on the php site. The...
4
by: peter.hrdy | last post by:
Hi guys. i have big problem with using fopen, fsockopen or curl. if i tried to use it on remote site it doesn't works. i've readed to much posts but didn't found anything helpfulll. fopen just...
1
by: Cleverbum | last post by:
I'm trying to write a script which downloads information from a number of websites analyses it and shows some results. The problem I'm having is that some sites seem to work perfectly while others...
1
by: deesw | last post by:
I have this code in my script. $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser,...
1
by: stillnight | last post by:
My web host has disabled fopen and now uses curl. I am a newbie to php so I am at a complete loss. I am trying to change the code in sendcard at sendcard.org to use curl. The beginning login will...
3
by: jeddiki | last post by:
Out of these, which one do you use most and why ? fsockopen, curl, fopen, file_get_contents,
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.