Crontab issues with PHP and image creation

.m0zilla

New Member
The context:I wrote a script which downloads an image from a server, sets white colour to transparent, and saves the image in root folder. It also saves a copy of the image in a separate folder "images" with date and time in its name. Because I don't exactly know when the image is refreshed, I keep hashes of images in a database alongside with the date of creation and file name.The problem:I want the script to run automatically every 5 minutes, so I created a crontab on my server (Ubuntu Server 12.04). Crontab does execute the script every 5 minutes, however it only adds new records to the database without saving the actual images. When I try and run the script manually trough the console or a web browser it works as it should: saves the images and updates the database records.Crontab (in case there's something wrong with it):\[code\]*/5 * * * * /usr/bin/php5 -f /var/www/radar.php > /var/www/logPHP.log 2>&1\[/code\]PHP code: \[code\]include 'mysql.php';$im = imagecreatefromgif("image_url");$hash = hash_file('md5', "image_url");$day = date("j");$month = date("n");$year = date("Y");$hour = date("G");$minute = date("i");$file = 'image' . $day . '-' . $month . '-' . $year . '_' . $hour . '_' . $minute . '.gif';echo "Hash: " . $hash . "<br />";echo "Start: " . date("H:i:s") . "<br />";$result = mysql_query("SELECT * FROM pictures WHERE hash = '$hash' LIMIT 1");$num = mysql_num_rows($result);if ($num == 0) { mysql_query("INSERT INTO pictures (year, month, day, hour, minute, hash, file) VALUES ('$year', '$month', '$year', '$hour', '$minute', '$hash', '$file')"); $dest = imagecreatetruecolor(799, 599); imagecopy($dest, $im, 0, 0, 10, 49, 799, 599); $color = imagecolorexact($dest, 255, 255, 255); imagecolortransparent($dest, $color); imagegif($dest, './image.gif'); imagegif($dest, './images/' . $file); imagedestroy($dest); imagedestroy($im);}echo "End: " . date("H:i:s");?><br /><img src="http://stackoverflow.com/questions/15871952/image.gif" />\[/code\]
 
Back
Top