can anyone give me an example of some lines of php code that can take a file from a website and copy it to a directory on my computer?
like copying http://www.site.com/files/foo.jpg to c:/files/foo.jpg
exec("wget http://www.site.com/files/foo.jpg");
and where does that put the file?
Where it executes from.
ok i put your line of code into test.php (with a real url ofcourse)
then i put test.php in my webroot directory
then i went to test.php through my browser
but the file wasn't copied to the directory
what am i doing wrong?
Works for me. You aren't on Windows are you?
yes, windows
Ok, so wget doesn't exist on there. wget is a Linux/GNU application. You may want to go here and download the Win32 port of it. Then it would work.
Otherwise, provided you have an up2date version of PHP, and you have fopen wrappers allowed, you could just use [man]copy[/man]
so
copy "http://www.site.com/files/foo.jpg";
would work? and that would be the only line of code i need?
You need to specify a destination also.
do i even have the right syntax there? I kinda just guessed
Well, no you don't. That why I provided the link.
copy("http://www.site.com/files/foo.jpg", 'C:\\foo.jpg');
it's copy(source file, destination file);
heres the code:
copy("http://whitch/ns/images/findnsscrim.gif", 'C:\foo.gif');
and heres the error message:
Warning: Unable to open 'http://whitch/ns/images/findnsscrim.gif' for reading: Invalid argument in c:\dn\test.php on line 3
You people always make me boot to Windows :p Okay, so I just did this, and it works fine
copy("http://phpbuilder.com/images/new-logo.gif",'C:\\blah.gif');
What PHP version you using? And does that file even exist?
oh.. i have 4.2.3
did anything change since then that would explain why this still isnt working?
Seriously, you should read the URL's I post to you
Note: As of PHP 4.3.0, both source and dest may be URLs if the "fopen wrappers" have been enabled. See fopen() for more details. If dest is an URL, the copy operation may fail if the wrapper does not support overwriting of existing files.
Meaning remote copies aren't allowed until 4.3.0.
crap, i updated php and apache wont start because it wont load the php4apache.dll