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!)

About this user

Sencer http://www.sencer.de

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

Upload all .gif and .jpg files in a directory to textpattern

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)

URL='http://www.mysite.com/textpattern/'
LOGIN='simplename'
PASS='yourpassword'

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

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


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


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.
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed