Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Upload all .gif and .jpg files in a directory to textpattern (See related posts)

This will upload all files in the current directory ending in jpg jpeg or gif through your textpattern-admin panel to your site.

Save this as a shell script, adjust the first 3 variables and excute. (Note: LOGIN and PASS should be ascii only, or else manually url-encoded)


COOKIE=$(curl -s -D - -d "p_userid=$LOGIN&p_password=$PASS" \
    $URL | head -n10 | sed -n 's/^Set\-Cookie\: //p')

if [ -z $COOKIE ] 
  echo "Can't log in."
  exit 1
  echo "Cookie: "$COOKIE

for file in $(ls -1|egrep '(gif)|(jpe?g)$') ; 
 echo "Sending "$file
 curl -s -H "Cookie: $COOKIE" -F "thefile=@$file" \
   -F "event=image" -F "step=image_insert" $URL > /dev/null

This will not output anything. But after it returns to the prompt, log in to textpattern and take a look into the image section.

Update: Added rudimentary check wether login is successful and basic progress meter.

Comments on this post

jason posts on May 27, 2005 at 22:56
Oh, that's a great snippet.
Sencer posts on May 28, 2005 at 14:05
Note: Make sure you have the slash at the end of the url.

are not the same. ;) (the first one will usually redirect)

Also: Filenames with blanks may make problems.

You need to create an account or log in to post comments to this site.

Related Posts