When I use this uploader, it works and actually uploads the file, but when I'm redirected back to the page that should display the small image, it only shows about 1/4 of the top of the image. If I refresh the page or click the "Browse..." button (without actually uploading a file) the complete image displays.
I thought it might be redirecting faster than it could upload or something, so I put a sleep(3) in there (I tried it all the way up to a ridiculous sleep(10)) but I'm still getting this first 1/4 of the image.
See attached screenshot...
What can cause this? How can I fix this?
Here is how it decides what to display:
<?php
//query for data
$query="SELECT * FROM `mybasicinfo` WHERE `owner` = '$workingon'";
$result=mysql_query($query)or die('FATAL ERROR :: MYSQL ERROR :: DATA RETRIEVAL FAILED!');
$rows=@mysql_num_rows($result);
if ($rows<1)
{
$_SESSION['fatal']="FAILED TO RETRIEVE DATA!";
header('location:index.php?page=index&s=0');exit;
}else{
$row=mysql_fetch_array($result);
//check imgpath
if (!isset($row['imgpath']) || empty($row['imgpath']) || $row['imgpath']=="")
{$imgpath="images/default.jpg";}else{$imgpath="http://www.example.com/testing/user_images/".$row['imgpath'];}
//echo"imgpath:$imgpath";
//if (!is_file("$imgpath")){echo"not a file"; $imgpath="images/default.jpg";}
}
?>
//then later on the page...
<img src="<?php echo"$imgpath";?>" width="225px" height="225px">
Here is the uploader:
<?php
session_start();
$stickernumber=$_SESSION['stickernumber'];
$workingon=$_SESSION['workingon'];
//connect to the database
mysql_connect('host', 'user', 'pass') or die (mysql_error());
mysql_select_db('phr') or die (mysql_error());
//save current information...
foreach($_POST as $key => $value)
{
if ($key!="image")
{
$keyfull = mysql_real_escape_string($key);
$keyarray = explode("_", $keyfull);
$keyname = $keyarray[0];
$keyuid = $keyarray[1];
$value = trim(mysql_real_escape_string($value));
//echo"keyname:$keyname<br>keyuid:$keyuid<br>value:$value<br><br>";
if ($keyname!="save1" && $keyname!="save2" && $keyname!="addnew" && $keyname!="remLen" && $keyname!="image" && $keyname!="MAX")
{
$query="UPDATE `mybasicinfo` SET `$keyname` = '$value' WHERE `uid` = '$keyuid'";//echo"<br><br>$query";
$exe=mysql_query($query)or die(mysql_error());
//'FATAL ERROR :: MYSQL ERROR :: UNABLE TO UPDATE MYSQL! (new_medication)'
$_SESSION['msg']="Saved Successfully!";
}
}//if key ! image
}//foreach
//now we try to upload the image
//first get the file name and clean it up...
$filename = $_FILES["image"]["name"];
if ($filename!="")
{
$filename = explode('.', $filename);
$filename[0] = html_entity_decode($filename[0]);
$filename[0] = str_replace($attackchars, '', $filename[0]);
$filename[0] = stripslashes($filename[0]);
$filename[0] = mysql_real_escape_string($filename[0]);
$filename[1] = html_entity_decode($filename[1]);
$filename[1] = str_replace($attackchars, '', $filename[1]);
$filename[1] = stripslashes($filename[1]);
$filename[1] = mysql_real_escape_string($filename[1]);
if (strlen($filename[2]>0))
{
$_SESSION['fatal']="Please check for extra .'s in your filname!";
header('location:../index.php?page=index&s=1');
exit;
}
//now find file type depending on $filename[1]
$fileend=strtolower($filename[1]); //put it in lower case...
if ($fileend=="jpg"){$imagetype=".jpg";}
if ($fileend=="jpeg"){$imagetype=".jpeg";}
if ($fileend=="png"){$imagetype=".png";}
if ($fileend=="gif"){$imagetype=".gif";}
if ($fileend=="bmp"){$imagetype=".bmp";}
if ($fileend!="jpg" && $fileend!="jpeg" && $fileend!="png" && $fileend!="gif" && $fileend!="bmp")
{
$_SESSION['fatal']="That \".$fileend\" file type is not supported!.";
header('location:../index.php?page=index&s=1');
exit;
}
$filenamearray = array($filename[0], $filename[1]);
$filename = implode('.', $filenamearray);
// THE ABOVE WORKS...the IE problem was pjpeg and x-png
$target = "../../user_images/$workingon"."$imagetype";
$imgpath = "$workingon"."$imagetype";
//This is our size condition
$filesize=$_FILES['image']['size'];
if ($filesize>500000)
{
$_SESSION['fatal']="Image upload failed: Image was larger than 500KB!";
header ('location:../index.php?page=index&s=1');
exit;
}
if ($filesize==0)
{
$_SESSION['fatal']="Image upload failed: Error during security checks.";
header ('location:../index.php?page=index&s=1');
exit;
}
//If everything is ok we try to save it to the server
$tmp_name=$_FILES['image']['tmp_name'];
if(move_uploaded_file($tmp_name, $target))
{
//store new img path...
mysql_query("UPDATE `mybasicinfo` SET `imgpath` = '$imgpath' WHERE `owner` = '$workingon'")or die (mysql_error());
sleep(3);
//header ('location:../index.php?page=index&s=1');
//exit;
}
else
{
$_SESSION['fatal']="Image upload failed: Error moving or renaming file.";
header('location:../index.php?page=index&s=1');
exit;
}
$_SESSION['msg']="Data Saved OK and Image Uploaded OK!";
//echo"<br>header1";
header('location:../index.php?page=index&s=1');//this ends if($filename)
exit;
}
//echo"<br>header2";
header('location:../index.php?page=index&s=1');
exit;
?>