Jump to content

Archived

This topic is now archived and is closed to further replies.

Yojance

Copying an IMG from a URL.

Recommended Posts

Here I'm again with a n00bie question.
I've been doing some research about doing this but I've not been able to gather enough sources and what I see, mainly I can understand it. Here is what I'm trying to achieve.

Lets say I know the URL of an image, for example [b]http://img165.imageshack.us/img165/3370/usflag0al.jpg[/b]
Now I want to save that jpg image into a directory located on my server.
Once I save it, I want to be able to display it on a site, using the image from my server.
How can I do that? and is it even possible?
Thanks to whoever can teach me a thing or two about working with images using php.
Thanks for reading.

Share this post


Link to post
Share on other sites
Go to that link you said, right click on the picture and hit save picture as, save it some where on your computer, transfer it your webserver and if it was named image1.jpg and it was in the same folder as the page you were tryin to display it on you could show it by using <img src="image1.jpg">  also you could just use <img src="<full URL>">

Share this post


Link to post
Share on other sites
Thank you for your fast response Corbin. You misunderstood what I'm trying to achieve. I want to write a script so php can do this automatically. When i say my server, I dont mean my computer, I mean the computer that hosts the site online.

I want to achieve something like www.imageshack.us, where instead of uploading the image from your computer, you tell it to get the image from a specific URL and host it on their servers. Thats exactly what I'm trying to achieve.

Share this post


Link to post
Share on other sites
i'll assume you're on PHP4

so you already know the URI of the image?
if you don't you can get the HTML of the page's URL file using [url=http://php.net/file_get_contents]file_get_contents()[/url] and the use [url=http://www.php.net/preg_match]preg_match()[/url] to match the value of the "src" attribute of the "img" tag.


so assuming you have the URI of the image at this point, you use [url=http://php.net/file_get_contents]file_get_contents()[/url] once again with the URI of the image as an argument so that it gets the contents of that image. now you use [url=http://www.php.net/fwrite]fwrite()[/url] to write that image to your disk and use that image with an img tag in your HTML to display it.


if you're on PHP5, [url=http://www.php.net/manual/en/function.file-put-contents.php]file_put_contents()[/url] is a more efficient alternative to fwrite()


hope that answered your question :)

Share this post


Link to post
Share on other sites
That sounds promising, can you provide me with a small example code so that I can understand it better. Im so lost at this. I read the info at php.net but it doesnt say much.

Share this post


Link to post
Share on other sites
why don't you give it a quick try and show me what you have and i will tell you what changes you need to make :)

just follow these steps while referring to the manual:
1. use file_get_contents() to get the image
2. use fwrite() to write the image to the disk.

Share this post


Link to post
Share on other sites
This is a copy right infrengement,

what the pont in being a computer programmer when stealing other users images lol..............

use flash. or illiustrator.

and if you havent got that use paint.

why not go all the way and make a search engine that can scan all relevent picturs banners ans so and save them all what a joke......................

Share this post


Link to post
Share on other sites
[quote author=Yojance link=topic=99217.msg390660#msg390660 date=1151868080]
Thank you for your fast response Corbin. You misunderstood what I'm trying to achieve. I want to write a script so php can do this automatically. When i say my server, I dont mean my computer, I mean the computer that hosts the site online.

I want to achieve something like www.imageshack.us, where instead of uploading the image from your computer, you tell it to get the image from a specific URL and host it on their servers. Thats exactly what I'm trying to achieve.


[/quote]

Hehe sorry I did misread what you said...

Share this post


Link to post
Share on other sites
[quote author=Koobi link=topic=99217.msg390678#msg390678 date=1151869800]
why don't you give it a quick try and show me what you have and i will tell you what changes you need to make :)

just follow these steps while referring to the manual:
1. use file_get_contents() to get the image
2. use fwrite() to write the image to the disk.
[/quote]

Will try that. Thanks.


[b]Redarrow[/b], im trying to write a script like www.imageshack.us, I will not be the one using the images :), its not for personal use :).

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.