473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 20639
Rik
On Tue, 24 Jul 2007 21:00:54 +0200, Férnas <ga*****@wideweb.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($urlinfo['path']);
$target = $savedir.'/'.$filename;
if(file_exists($target) && !$overwrite){
//break up file in parts:
$pathinfo = pathinfo($target);
//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($savedir);
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_contents('mylogo.gif',
file_get_contents('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...@gmail.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_contents('mylogo.gif',
file_get_contents('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.php>
<gosha bine>
<Wed, 25 Jul 2007 10:43:24 +0200>
<46***********************@read.cnntp.org>
file_put_contents('mylogo.gif',
file_get_contents('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
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...
2
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...
2
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
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...
0
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
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...
2
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
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...
5
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.