Php > Graphics
Create thumbnails and ftp em via command line
Create thumbnails and ftp em via command line #!/usr/local/bin/php 126, "height" => 227 ); $thumbnails[] = array( "width" => 240, "height" => 433 ); $thumbnails[] = array( "width" => 74, "height" => 131 ); # Setup FTP Connections $ftpconfig[] = array( "host" => "host1.foo.bar", "user" => "ftpuser", "password" => "ftppass", "path" => "/any/place/you/like", "retries" => 5, "retry_delay" => 10, ); $ftpconfig[] = array( "host" => "host2.foo.bar", "user" => "ftpuser", "password" => "ftppass", "path" => "/any/other/place/you/like", "retries" => 5, "retry_delay" => 10, ); $ftpconfig[] = array( "host" => "host3.foo.bar", "user" => "ftpuser", "password" => "ftppass", "path" => "/even/an/offsite/backup/location", "pasv" => true, "retries" => 5, "retry_delay" => 10, ); ### # Begin Functions # Generate the new thumbnail name function new_thumb_name($filename,$width,$height) { # Get just the filename, cut off the extension $base = basename($filename,".pdf"); $filecomponents = explode("_",$base); # Generate the file name using the agreed upon standard $newfilename = sprintf("%s_%s_%s_%sw_%sh.gif",$filecomponents[0],$filecomponents[1],$filecomponents[2],$width,$height); # Return the filename return $newfilename; } # Generate the ftp destination name function send_via_ftp(&$files,&$ftpconfig) { foreach ($ftpconfig as $ftp) { # Reset the loop counter to 1 $i = 0; # Do the loop x number of times while (++$i <= $ftp['retries']) { # set up basic connection $conn_id = ftp_connect(strval($ftp['host'])); # If we successfully connected... if ($conn_id) { # login with username and password $login_result = ftp_login($conn_id, $ftp['user'], $ftp['password']); # Needs PASV? # If PASV is set in the ftpconfig block use it. if (array_key_exists('pasv',$ftp) && $ftp['pasv']) { ftp_pasv($conn_id,true); } } # check connection if ((!$conn_id) || (!$login_result)) { fwrite(STDERR,"FTP connection has failed! Attempt #$i of " . $ftp['retries'] . "\n"); fwrite(STDERR,"Attempted to connect to " . $ftp['host'] . " for user " . $ftp['user'] . "\n"); if ($conn_id) {ftp_close($conn_id);} sleep($ftp['retry_delay']); continue; } else { foreach ($files as $file) { # upload the file $upload = ftp_put($conn_id, basename($file), $file, FTP_BINARY); # check upload status if (!$upload) { fwrite(STDERR,"FTP upload of $file to " . $ftp['host'] . " has failed!\n"); reset($files); ftp_close($conn_id); sleep($ftp['retry_delay']); continue; } } reset($files); } # close the FTP stream ftp_close($conn_id); break; } } } # End Functions ### ### # Begin Main Code foreach ($thumbnails as $thumbnailarray) { $destinations = array(); $width = $thumbnailarray['width']; $height = $thumbnailarray['height']; $newfilename = new_thumb_name($filename,$width,$height); $newfile = "/PDF/Thumbnails/" . $newfilename; # Use ImageMagic+Ghostscript to do the thumbnail generation # at desired height/width $error = `/usr/local/bin/convert -trim -thumbnail ${width}x${height} "$filename" $newfile`; $files[] = $newfile; } send_via_ftp(&$files,&$ftpconfig); ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage