Hi,
If I have user type in a URL: such as: http://www.somedomain.com/testimage.jpg, I want my PHP script to read that file by using given URL and write the file to the server. (To save testimage.jpg to the server). Can someone please help me with a simple tutorial example code.
Thanks a lot.
Surely the image is already on the server?
fean0r wrote:Surely the image is already on the server?
Yeah. I have a membership system where I allow user to paste a jpg url to upload the file to my server store as their avatar image file.
[man]file_get_contents[/man] to get the contents of the image, [man]fopen[/man] and [man]fwrite[/man] to save the contents.
drew010 wrote:[man]file_get_contents[/man] to get the contents of the image, [man]fopen[/man] and [man]fwrite[/man] to save the contents.
Can you give me some simple code?
<?php $data = file_get_contents('http://www.google.com/'); $fp = fopen('./google.txt', 'w+'); fwrite($fp, $data); fclose($fp); ?>
drew010 wrote:<?php $data = file_get_contents('http://www.google.com/'); $fp = fopen('./google.txt', 'w+'); fwrite($fp, $data); fclose($fp); ?>
Thanks a lot. It works now.