Hello all.
I have this script which scales an image. It works fine on my home computer, but when I take it to my system at work, PHP merely displays the URL of the page. The web app and the MySQL database are exact copies of each other. Perhaps someone can tell me what is happening here?
Many many thanks to anyone who can help.
PHP Code:<?php
/* THE PURPOSE OF THIS FILE IS TO UPLOAD, THEN SCALE AN IMAGE, IF NEEDED */
/* SECURITY LOCAL TO THIS SCRIPT */
if(
isset($GLOBALS['post']['id'])
&&
isset($_FILES['txt_file'])
) {
/* THE USER HAS PASSED */
/* UPLOAD THE IMAGE, IF APPLICABLE */
if(
strlen($_FILES['txt_file']['name'])>0
) {
/* SPLIT THE POSTED FILE NAME */
$split_name=explode(".", $_FILES['txt_file']['name']);
/* SET THE FILE EXTENSION */
$file_extension='.'.end($split_name);
/* NEW FILENAME */
$new_file_name=$GLOBALS['post']['id'].'_'.mktime().$file_extension;
/* READ THE TEMPORARY FILE */
$temp_name = $_FILES['txt_file']['tmp_name'];
$temp_file = fopen($temp_name, "r");
$binary_data = fread($temp_file, fileSize($temp_name));
/* TURN ON ERROR REPORTING */
$old_error_reporting = error_reporting(E_ALL & ~(E_WARNING));
/* CREATE THE FILE */
$file_path = '../_upload/'.$new_file_name;
touch($file_path);
$fp=fopen($file_path, 'w');
fwrite($fp, $binary_data);
fclose($fp);
/* TURN OFF ERROR REPORTING */
error_reporting($old_error_reporting);
/* CHECK THE IMAGE DIMENSIONS */
$image=getimagesize($file_path);
$old_width=$image[0];
$old_height=$image[1];
/* NEEDED FOR RESIZING IMAGES */
if(
$old_width>375 || $old_height>375
) {
/* NEED TO DETERMINE WHICH IS GREATER, HEIGHT OR WIDTH */
if(
$old_height>$old_width
||
$old_height==$old_width
) {
$divider=ceil($old_height/375);
} else {
$divider=ceil($old_width/375);
}
/* NOW SET THE $new_height AND $new_width VARIABLES */
$new_height=floor($old_height/$divider);
$new_width=floor($old_width/$divider);
} else {
$new_height=$old_height;
$new_width=$old_width;
}
/* INITIALIZE THE SOURCE AND OUTPUT FILE NAMES */
$source_file_name='../_upload/'.$new_file_name;
$output_file_name='../../_images/_products/'.$new_file_name;
$thumbnail_file_name='../../_images/_products_thumbnails/'.$new_file_name;
/* THE CONTENT TYPE */
if($file_extension=='.jpg') {
header('Content-type: image/jpeg');
}
/* FOUND THE FOLLOWING FIX HERE */
/* http://worcesterwideweb.com/2008/03/17/php-5-and-imagecreatefromjpeg-recoverable-error-premature-end-of-jpeg-file/ */
ini_set('gd.jpeg_ignore_warning', 1);
/* RESAMPLE THE IMAGE */
$image_p=imagecreatetruecolor($new_width, $new_height);
$image=imagecreatefromjpeg($source_file_name);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
/* CREATE THE IMAGE */
if($file_extension=='.jpg') {
imagejpeg($image_p,$output_file_name,100);
}
/* RESAMPLE THE IMAGE */
$image_p2=imagecreatetruecolor(100, 100);
$image=imagecreatefromjpeg($source_file_name);
imagecopyresampled($image_p2, $image, 0, 0, 0, 0, 100, 100, $old_width, $old_height);
/* CREATE THE THUMBNAIL IMAGE */
if($file_extension=='.jpg') {
imagejpeg($image_p2,$thumbnail_file_name,100);
}
/* CALL THE CLASS FUNCTION TO BUILD A QUERY TO UPDATE A PRODUCT IMAGE */
if($file_extension=='.jpg') {
$GLOBALS['cms_queries']->update_product_image($GLOBALS['post']['id'],$new_file_name);
}
/* SINCE I'VE ALREADY SENT HEADERS I NEED TO REDIRECT MANUALLY */
echo '<html>';
echo '<head>';
echo '<title>REDIRECTING</title>';
echo '<meta http-equiv="refresh" content="0;url=../'.$GLOBALS['global_admin_page'].'?a=040&red=041&thank='.mktime().'" />';
echo '</head>';
echo '<body>';
echo '</body>';
echo '</html>';
}
}
?>




Reply With Quote