Anything which will do this?

Associate
Joined
17 Mar 2004
Posts
1,562
I want to batch upload some photos to some forums.

Instead of having to upload one by one via Photobucket etc, is there any way I can FTP them all to my webspace and run some sort of script which will give me the URL's in one long list?

Cheers.
 
Assuming you can access them in a dir listing from http, I just hacked together something that should do the job.

Code:
import re
import urllib2

PREFIX = "www.example.net/images/"

images = [] 
apat = re.compile(r'^<a.*href=["|'']([^"'']*)["|'']', re.IGNORECASE)
cpat = re.compile(r'(<[^>]*>)')

def readurl(url):
  r = urllib2.urlopen(url)
  s = ''
  while True:
    line = r.read(1024)
    s += line 
    if len(line) < 1024:
      break
  return s


s = readurl(PREFIX)
l = cpat.split(s)
i = 0

while i < len(l):
  if l[i].startswith('<A HREF'):
    images.append(apat.match(l[i]).group(1))
  i = i + 1

for i in images:
  print PREFIX + i

Change PREFIX to your desired url. Then save as dirlist.py and run as

python dirlist.py > filelist.txt

For example.

Or if you have lynx installed:

Code:
lynx -dump "http://www.example.com/" | egrep -o "http:.*.jpg" >links.txt

Change jpg for png or whatever you want.
 
Last edited:
got php? place the script in the directory with the files....

Code:
<?php
$here = 'http://domain.com/folder/'; //change this to full url of your images folder
foreach(glob('*.jpg') as $image) {
	echo '[img]'.$here.$image.'[/img]'; //remove the img tags if you don't need them but would be handy for forums i'm guessing
        echo '<br>';
}
?>

edit: meh, too slow. :p
 
Last edited:
Back
Top Bottom