PDA

View Full Version : Issues with image uploader



YourDirector
04-11-2012, 03:44 PM
I'm using the code below to upload an image, resize it, make a thumbnail copy, save both to a unique folder created earlier on and then save the file names to a database. (It also checks if there was an image there before and if so deletes it);

Unfortunately, this is currently causing an ERROR 500 - Internal Server Error. Ideas?




$evt=$_POST['evt'];

include("connect.php");

$query="SELECT * FROM events WHERE id='$evt'";
$result=mysql_query($query);
$num=mysql_numrows($result);

$i=0;
while($i<$num){
$name=mysql_result($result,$i,"name");
$primaryimage=mysql_result($result,$i,"primaryimage");
$primarythumb=mysql_result($result,$i,"primarythumb");
};

$imgroot = "../imagehub/events/";
$nwfldr = $evt.$name;
$target = $imgroot.$nwfldr."/";
$targetimage = $target . time() . basename($_FILES['newppic']['name']);
$targetthumb = $target . "tm_" . time() . basename($_FILES['newppic']['name']);

$ppic = (time() . basename($_FILES['newppic']['name']));
$ppictm = ("tm_" . time() . basename($_FILES['newppic']['name']));





if(move_uploaded_file($_FILES['newppic']['tmp_name'],$targetimage)){

include('SimpleImage.php');
$image = new SimpleImage();
$image->load($targetimage);
if ($image->getwidth() > 600){
$image->resizeToWidth(600);
}
if ($image->getheight() >200){
$image->resizeToHeight(200);
};


$image->save($targetimage);
};

if(move_uploaded_file($_FILES['newppic']['tmp_name'],$targetthumb)){

$image = new SimpleImage();
$image->load($targetthumb);
if ($image->getwidth() > 100){
$image->resizeToWidth(100);
}
if ($image->getheight() >33){
$image->resizeToHeight(33);
};

$image->save($targetthumb);

$query="UPDATE events SET primaryimage='$ppic' primarythumb='$ppictm' WHERE id='$evt'";
mysql_query($query);
mysql_close();

if(!$primaryimage == ""){
$delete = $target.$primaryimage;
$deletetm = $target.$primarythumb;
unlink($delete);
unlink($deletetm);
};


header('Location: ../event?evt='.$evt);
}else{
echo "ERROR";
};

Thanks YD

angst
04-11-2012, 03:46 PM
check permissions on the folder it's uploading to, and then follow your code line by line to see where the error is occurring. 500 error is pretty common.