Apache scripting: serving images via a shell script
This example shows a way to get jpeg images via a shell script helper using Apache web server. Root access is required for this to work properly. Perhaps a dedicated server, VPS or even your own computer may be used.
Writing the Apache script for image serving
Let's write a simple script for cat'ing the testimage.jpg. It tries to cd into the 'imageserviceagent' home dir, and if that's successful, it outputs the jpg image called testimage.jpg. The cd (change directory) command is here for the other examples as we can get rid of quite a few absolute paths which makes things simpler.
#!/bin/sh cd /home/imageserviceagent/ 2>/dev/null > /dev/null if [ $? -eq 0 ]; then LEN=`/usr/bin/stat -c %s /home/imageserviceagent/testimage.jpg` /bin/echo "Content-Length: $LEN" /bin/echo "Content-type: image/jpeg" /bin/echo "" /bin/cat /home/imageserviceagent/testimage.jpg exit fi
Make sure the script is in correct location (/usr/lib/s) and has the proper access rights with chmod a+x.
Next, check that your script is working by running it with your browser:
You should see the jpeg image on your browser! If not, check your /var/log/apache2/error.log for tips on what went wrong.