Jump to content

Flaky PHP Jpg Upload Question


pixelsketch

Recommended Posts

I have a PHP script which works fine for me (I've tested a million times on MAC OSX and Windows XP running, Safari, Firefox, and IE - all work fine) the script is supposed to allow a user to browse for a JPG file on their computer, shrink that JPG, and save two copies, one at 200x200 and another small thumbanil copy.

** I HAVE PASTED THE SCRIPT BELOW**

The problem is that I have a user on a PC running Internet Explorer who needs to use this script frequently, and he says that sometimes the script will work, other times (most times) it will not. You can see a result of what his photo looks like when it is uploaded by going to:

[url=http://www.reddeerpowersports.com/uploads/33.jpg]http://www.reddeerpowersports.com/uploads/33.jpg[/url]

Now, this seems to be happening on the server?????, since the page can be accessed by him fine, and the script works fine for me. In fact portions of the script are working (ie, the image begins to upload, and all UPDATES to the database are made, but for some reason, when he tries to attach a photo, it just hangs up and gives him this half rendered image you see by visiting the above URL. 

Anyone see anything obvious??
Thank you in advance for your help,




The script is as follows:








_______PHP SCRIPT
<?
extract($HTTP_POST_VARS);
$db = mysql_connect('***********', '***********', '***********');
mysql_select_db('***********', $db);

$sql = "INSERT INTO  `forsale` (  `id` ,  `thumb` ,  `photo` ,  `title` ,  `category` ,  `details` ,  `hours` ,  `price` )
VALUES (
'',  '',  '',  '$title',  '$category',  ' $details',  '$hours',  '$price'
)";
mysql_query($sql, $db);

$numbereditem=mysql_insert_id();




if (is_uploaded_file($_FILES['file']['tmp_name'])) {
$filename=$_FILES['file']['tmp_name'];
$photoname=$numbereditem;
$thumbname=$photoname . 'thumb';
$newlargepath="http://www.reddeerpowersports.com/uploads/$photoname.jpg";
$newsmallpath="http://www.reddeerpowersports.com/uploads/$thumbname.jpg";
$badfile=1;

if ($_FILES['file']['type'] == "image/jpg" || $_FILES['file']['type'] == "image/jpeg" || $_FILES['file']['type'] == "image/pjpeg"){$badfile=0;}



$target_path = "../uploads/" . $photoname . ".jpg";
move_uploaded_file($_FILES['file']['tmp_name'], $target_path);
$source = imagecreatefromjpeg($target_path);
$width=imagesx($source);
$height=imagesy($source);
$nw=200;
$nh=(($height*200)/$width);
$thumb = imagecreatetruecolor($nw, $nh);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $nw, $nh, $width, $height);
imagejpeg($thumb, $target_path, 60);
if (!isset ($nw)){$nw=$width;}
if (!isset ($nh)){$nh=$height;}
$sql3="UPDATE forsale SET photo ='$newlargepath' WHERE `id` = '$numbereditem'";
mysql_query($sql3);

$source = imagecreatefromjpeg($target_path);
$target_path = "../uploads/" . $photoname . "thumb.jpg";


$width=imagesx($source);
$height=imagesy($source);
$nw=60;
$nh=(($height*60)/$width);
$thumb = imagecreatetruecolor($nw, $nh);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $nw, $nh, $width, $height);
imagejpeg($thumb, $target_path, 60);
if (!isset ($nw)){$nw=$width;}
if (!isset ($nh)){$nh=$height;}





$sql3="UPDATE forsale SET thumb ='$newsmallpath' WHERE `id` = '$numbereditem'";
mysql_query($sql3);



}

header('Location: used.php');
?>
Link to comment
https://forums.phpfreaks.com/topic/30821-flaky-php-jpg-upload-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.