homepage Welcome to WebmasterWorld Guest from 54.226.0.225
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Images and PHP
Just a quickie regarding what is possible
Nick_W




msg:1294346
 5:19 pm on Jun 3, 2003 (gmt 0)

Hi all,

I've done a bit of image uploading before and although it's not easy, it's not really hard either right?

Has anyone done this though: Set it up so that you could copy the image url (from another server) and have the script download the image and treat it like it was uploaded?

With me? - I'm building affiliate db's and need to automate the process of uploading product photos as much as possible.

Many thanks, hope it's understandable!

Nick

 

jatar_k




msg:1294347
 7:36 pm on Jun 3, 2003 (gmt 0)

Since no one seems to have any grand insight the first things that come to mind are curl, GD or a socket. Haven't done anything like that really though.

I just get them to upload from their hard drive.

Nick_W




msg:1294348
 7:37 pm on Jun 3, 2003 (gmt 0)

Yes, I may just try it out to see if it'll work with a 'browse' button on a form.....

thanks jatar...

Nick

Nick_W




msg:1294349
 7:39 pm on Jun 3, 2003 (gmt 0)

actually, saying that, there are lots of file functions that open urls etc, why would an image be any different?

If I could open the image and save it to a var then........ I'll have to think about this ;)

Nick

jatar_k




msg:1294350
 7:42 pm on Jun 3, 2003 (gmt 0)

which is why I thought of curl. If you want to open a remote opage somewhere that is how to do it. Then when saving it you may need to use GD to test the type and then save/create a new image.

Gibble




msg:1294351
 7:45 pm on Jun 3, 2003 (gmt 0)

just my $0.02

curl and such are quite slow

jatar_k




msg:1294352
 7:46 pm on Jun 3, 2003 (gmt 0)

what would you suggest then Gibble?

Nick_W




msg:1294353
 7:47 pm on Jun 3, 2003 (gmt 0)

I don't have root. Curls an add on right?

Nick

jamesa




msg:1294354
 7:58 pm on Jun 3, 2003 (gmt 0)

Yea, cURL [curl.haxx.se] is a command line program. Easiest way to run it from PHP is using one of the backtick-type commands.

% curl h-ttp://server.tld/image.gif > image.gif

Gibble




msg:1294355
 8:04 pm on Jun 3, 2003 (gmt 0)

If you want to use cURL with PHP
www.phpfreaks.com/tutorials/49/1.php

I don't know what to recommend, I just know it's not fast :(

I suppose you could use wget from the command line...

[edited by: jatar_k at 8:12 pm (utc) on June 3, 2003]
[edit reason] delinked [/edit]

Nick_W




msg:1294356
 8:10 pm on Jun 3, 2003 (gmt 0)

I can execute command line apps from PHP?

Nick

jamesa




msg:1294357
 8:43 pm on Jun 3, 2003 (gmt 0)

yes, there's a few different ways to execute a shell program via PHP. Take a look at the 'passthru' function which I *think* would be the most appropriate for what you're trying to do. All of the methods are listed here [us3.php.net]

ggrot




msg:1294358
 8:54 pm on Jun 3, 2003 (gmt 0)

If you want to do command line, you could also to wget:

wget <url>
will get the file at the specified url and dump it into your current directory. to specify a directory and name, use
wget --output-document=<filename> <url>

You can also use --limit-rate=20kb for example to limit the max download rate at 20kb if you dont want to paralyze your server or the remote server. There are also options for specifying lists of files and such, just use the man page.

Also, php can directly download files on it's own and also write them:
[us3.php.net...]
fopen works the same on remote urls as local files if you are reading. Works for images just fine. Now the trick then becomes finding all the image urls.

mapostel




msg:1294359
 11:25 pm on Jun 3, 2003 (gmt 0)

Wouldn't it be the most straightforward way to use a php function to read the contents of a URL (i.e. the picture file) into a variable? There is file_get_contents() as of PHP 4.3 (see php docs). I haven't used it yet but it sounds like the one that you want.

DrDoc




msg:1294360
 3:14 am on Jun 4, 2003 (gmt 0)

Why not just use GD? [us2.php.net...]

imagecreatefromgd2 -- Create a new image from GD2 file or URL
imagecreatefromgd2part -- Create a new image from a given part of GD2 file or URL
imagecreatefromgd -- Create a new image from GD file or URL
imagecreatefromgif -- Create a new image from file or URL
imagecreatefromjpeg -- Create a new image from file or URL
imagecreatefrompng -- Create a new image from file or URL
imagecreatefromstring -- Create a new image from the image stream in the string
imagecreatefromwbmp -- Create a new image from file or URL
imagecreatefromxbm -- Create a new image from file or URL
imagecreatefromxpm -- Create a new image from file or URL

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved