Jump to content


Photo

Copying an IMG from a URL.


  • Please log in to reply
8 replies to this topic

#1 Yojance

Yojance
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 02 July 2006 - 06:52 PM

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 http://img165.imageshack.us/img165/3370/usflag0al.jpg
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.

#2 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 02 July 2006 - 06:57 PM

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>">
Why doesn't anyone ever say hi, hey, or whad up world?

#3 Yojance

Yojance
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 02 July 2006 - 07:21 PM

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.



#4 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 02 July 2006 - 07:32 PM

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 file_get_contents() and the use preg_match() 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 file_get_contents() once again with the URI of the image as an argument so that it gets the contents of that image. now you use fwrite() 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, file_put_contents() is a more efficient alternative to fwrite()


hope that answered your question :)

#5 Yojance

Yojance
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 02 July 2006 - 07:39 PM

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.

#6 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 02 July 2006 - 07:50 PM

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.

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 July 2006 - 07:50 PM

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......................
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 02 July 2006 - 07:54 PM

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.



Hehe sorry I did misread what you said...
Why doesn't anyone ever say hi, hey, or whad up world?

#9 Yojance

Yojance
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 02 July 2006 - 08:04 PM

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.


Will try that. Thanks.


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users