Welcome to WebmasterWorld Guest from 54.196.232.162

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Images and PHP

Just a quickie regarding what is possible

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

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 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

7:36 pm on June 3, 2003 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 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.

7:37 pm on June 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


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

thanks jatar...

Nick

7:39 pm on June 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 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

7:42 pm on June 3, 2003 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 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.
7:45 pm on June 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 13, 2002
posts:662
votes: 0


just my $0.02

curl and such are quite slow

7:46 pm on June 3, 2003 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


what would you suggest then Gibble?
7:47 pm on June 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


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

Nick

7:58 pm on June 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2002
posts:710
votes: 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
8:04 pm on June 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 13, 2002
posts:662
votes: 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]

8:10 pm on June 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


I can execute command line apps from PHP?

Nick

8:43 pm on June 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2002
posts:710
votes: 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]
8:54 pm on June 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 4, 2001
posts:997
votes: 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.

11:25 pm on June 3, 2003 (gmt 0)

New User

10+ Year Member

joined:Feb 23, 2003
posts:27
votes: 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.
3:14 am on June 4, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
posts:6807
votes: 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