Yojance Posted July 2, 2006 Share Posted July 2, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13482-copying-an-img-from-a-url/ Share on other sites More sharing options...
corbin Posted July 2, 2006 Share Posted July 2, 2006 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>"> Quote Link to comment https://forums.phpfreaks.com/topic/13482-copying-an-img-from-a-url/#findComment-52147 Share on other sites More sharing options...
Yojance Posted July 2, 2006 Author Share Posted July 2, 2006 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 Link to comment https://forums.phpfreaks.com/topic/13482-copying-an-img-from-a-url/#findComment-52157 Share on other sites More sharing options...
Koobi Posted July 2, 2006 Share Posted July 2, 2006 i'll assume you're on PHP4so 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/13482-copying-an-img-from-a-url/#findComment-52163 Share on other sites More sharing options...
Yojance Posted July 2, 2006 Author Share Posted July 2, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13482-copying-an-img-from-a-url/#findComment-52166 Share on other sites More sharing options...
Koobi Posted July 2, 2006 Share Posted July 2, 2006 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 image2. use fwrite() to write the image to the disk. Quote Link to comment https://forums.phpfreaks.com/topic/13482-copying-an-img-from-a-url/#findComment-52174 Share on other sites More sharing options...
redarrow Posted July 2, 2006 Share Posted July 2, 2006 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...................... Quote Link to comment https://forums.phpfreaks.com/topic/13482-copying-an-img-from-a-url/#findComment-52176 Share on other sites More sharing options...
corbin Posted July 2, 2006 Share Posted July 2, 2006 [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... Quote Link to comment https://forums.phpfreaks.com/topic/13482-copying-an-img-from-a-url/#findComment-52179 Share on other sites More sharing options...
Yojance Posted July 2, 2006 Author Share Posted July 2, 2006 [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 image2. 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 :). Quote Link to comment https://forums.phpfreaks.com/topic/13482-copying-an-img-from-a-url/#findComment-52186 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.