Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    118
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Issues with image uploader

    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?

    PHP Code:

    $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

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •