473,765 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Save a image from web given the image url

Hello all,

How can I save a image that is on internet (eg:
http://www.agalera.com.br/_img/layout/logo.gif)???

I would like to save the image on my server...

many thanks

Jul 24 '07 #1
4 20657
Rik
On Tue, 24 Jul 2007 21:00:54 +0200, Férnas <ga*****@widewe b.com.brwrote:
Hello all,

How can I save a image that is on internet (eg:
http://www.example.com/_img/layout/logo.gif)???

I would like to save the image on my server...
If allow_url_fopen[1] is enabled:
<?php

$url = 'http://example.com/image.jpg';
$savedir = '/tmp'; //or anything else you want
$overwrite = true; //or false if image has to be renamed on duplicate

$urlinfo = parse_url($url) ;
$filename = basename($urlin fo['path']);
$target = $savedir.'/'.$filename;
if(file_exists( $target) && !$overwrite){
//break up file in parts:
$pathinfo = pathinfo($targe t);
//max 50 tries
$max = 50;
//loop
for($i = 1;$i<=$max;$i++ ){
$target = $pathinfo['dirname']. '/' . $pathinfo['filename'] . '[' . $i
.. '].' . $pathinfo['extention'];
//break on success, do not use file_exists to avoid race
$fh = @fopen($target, 'x');
if($fh) break;
}
//alternatively, if you don't care about the name, you can just:
//$target = tempnam($savedi r);
if(!$fh) die('Too many retries, no unique filename found.');
} else {
$fh = fopen($target,' w');
}
$check = fwrite($fh,file _get_contents($ url));
fclose($fh);
echo (($check) ? 'Successfully saved '.$target : 'Failure');
?>

[1]http://nl2.php.net/manual/en/ref.filesystem. php
--
Rik Wasmus
Jul 24 '07 #2
On 24.07.2007 21:00 Férnas wrote:
Hello all,

How can I save a image that is on internet (eg:
http://www.agalera.com.br/_img/layout/logo.gif)???

I would like to save the image on my server...

many thanks
file_put_conten ts('mylogo.gif' ,
file_get_conten ts('http://www.agalera.com .br/_img/layout/logo.gif'));

;)
--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Jul 25 '07 #3
On 25 jul, 05:43, gosha bine <stereof...@gma il.comwrote:
On 24.07.2007 21:00 Férnas wrote:
Hello all,
How can I save a image that is on internet (eg:
http://www.agalera.com.br/_img/layout/logo.gif)???
I would like to save the image on my server...
many thanks

file_put_conten ts('mylogo.gif' ,
file_get_conten ts('http://www.agalera.com .br/_img/layout/logo.gif'));

;)

--
gosha bine

makrell ~http://www.tagarga.com/blok/makrell
php done right ;)http://code.google.com/p/pihipi
Thank's all.. It worked!!!

your help was very appreciated...

Regards

Jul 25 '07 #4
<comp.lang.ph p>
<gosha bine>
<Wed, 25 Jul 2007 10:43:24 +0200>
<46************ ***********@rea d.cnntp.org>
file_put_conten ts('mylogo.gif' ,
file_get_conten ts('http://www.agalera.com .br/_img/layout/logo.gif'));
Good code .
Jul 26 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11631
by: ningjun.wang | last post by:
Hello: My html file contains the following image link: <a href="some_url"><img src="MyImage.gif"></a> How can I use Javascript to find out the value of some_url for the given image name "MyImage.gif"? I know how to get the image object with a given name (e.g.
2
3893
by: Dave Bootsma | last post by:
Is it possible to programatically save a certain image from a certain web page? I want to automatically get a specific graphic from a specific web page programatically so I can automate the task. I know I can NAVIGATE to the page with the MS web browser control, but at that point I am stumped as to wether I can even save the page... TIA
2
11331
by: Bassem | last post by:
Hi all... I searhed for a code to save and retrieve image from SQL database using Data adapter but I didn't found anything. Thanks, Bassem.
0
4142
by: prakash | last post by:
Dear Friends I am new guy to Visual C++.NET I've program to save website as a image vc++.net . It have a function "SaveSnapshot" to save the webpage as an image On that function ifor saving as a image it uses image.Save method() This image.Save function have two overloaded form's first one is file name
0
1109
by: Audrey | last post by:
Bonjour à ts, Est il possible d'accéder à une vidéo image par image ? Avec quel composant ? Je suis sur VS2003 et mon langage c'est C# Merci par avance
0
3128
by: aparth | last post by:
I've been trying and failing to create an image map that contains a tiled background image underneath the main image. My image map is 600px in height. I want the main image (img_bottom.jpg) to only cover the bottom 100px of the map (and the background to fill the rest of the space). The height of the main image will change, which is why I want to leave the empty space as a tiled background image. #my_map { display: block; height:...
2
6403
by: rams083 | last post by:
how can i display an image on Image Control from Database, asp.net 2.0 vb? please help me... thank you for your reply...
0
1382
by: manjitsarma | last post by:
I need to display an image in 'Image Control' of aspx page.Now the image is displayed in the aspx page itself.But I need to display it in 'Image Control'.This is a map application and the image is accessed from Webservice. The part of code to display the image in aspx page is added here. Bitmap bmp = new Bitmap(img, 100, 100); Graphics g = Graphics.FromImage(bmp); g.DrawImage(img, 100, 100);
5
1885
by: faizalahmd | last post by:
How to display image in image control , which is retrieved from the data base . using c# in asp.net regards, FAIZAL AHMED.H
2
2395
by: SAINTJAB | last post by:
Hi, Guys, am trying this program where I used openDialog to allow the user to select an image. This image is load into a pictureBox called MemberPics. After that, I want to save the selected image with its file name and retrieve(load into another pictureBox called display) it in another form. In this case, i want to use the image filename for the retrieval so that different user can use different images. Please help me.
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.