I'm trying to download a list of files with php to a directory on my host, however i am recieved the following error ... "[function.fopen]: failed to open stream: HTTP wrapper does not support writeable connections in" $filename = 'http://remotefilehere.com'; $handle = fopen("$filename", "w"); fwrite($handle, 'download/'); fclose($handle); PHP: Is something wrong here?
Dude, First of all, fopen needs a filename, you put there... $filename = "http://somesite.com" <-- this is not a file You could have at least put, $filename = "http://somesite.com/index.php", Im not sure but this could work if the site has read permission to all. Im not sure because I used fopen only on local files and not a file you get from another site. The error is saying something about HTTP, thats maybe because you are accessing a file from another machine. Lastly, just a minor thing, dont put quotes on the filename inside fopen... fopen("$filename", "r") this should be --> fopen($filename, "r");
I analyzed your code a bit more, I think what you want to do is add a directory on your site. If thats the case you should use the function mkdir() Hope my posts help..
Your all concept is wrong. Your php code is running on your site, so you don't need (and can't) access it through http. Here is an example on how to fetch a file and write it. $external = file_get_contents('http://www.somesite.com/file.txt'); $save_filename = 'downloads/try.txt'; $handle = fopen($save_filename, "w"); fwrite($handle, $external); fclose($handle); Make sure "downloads" dir is created on your server with write permissions. (btw, if you use PHP5, you can simply use file_put_contents and skip the all fopen/fwrite/fclose thing)