Plz help for uploading image

Discussion in 'PHP' started by salayhin, Jun 5, 2010.

  1. #1
    I am trying following script for uploading image but their is nothing happen or no error message.
    Please help me...

    Here is my code...

    ###########################
    <?php
    //session_start();
    //Include database connection details
    require_once('../connection/config.php');


    $teacher_id=$_GET['id'];
    echo "$teacher_id";


    $image_tempname = $_FILES['image_filename']['name'];

    $today = date("d-m-Y");

    //upload image and check for image type
    $ImageDir ="images_dir/";

    //**INSERT THIS LINE:
    $ImageThumb = $ImageDir . "thumbs/";
    //**END OF INSERT

    $ImageName = $ImageDir . $image_tempname;

    if (move_uploaded_file($_FILES['image_filename']['tmp_name'],
    $ImageName)) {

    //get info about the image being uploaded
    list($width, $height, $type, $attr) = getimagesize($ImageName);



    //**insert these new lines
    if ($type > 3) {
    echo "Sorry, but the file you uploaded was not a GIF, JPG, or " .
    "PNG file.<br>";
    echo "Please hit your browser's 'back' button and try again.";
    } else {

    //image is acceptable; ok to proceed

    //**end of inserted lines

    //insert info into image table

    $sql = "INSERT INTO `teacher_image`
    (id,teacher_ID,image_name,date)
    VALUES
    ('','$teacher_id','','$today')";
    $insertresults = mysql_query($sql ) or die(mysql_error());

    $lastpicid = $teacher_id;

    //change the following line:
    $newfilename = $ImageDir . $lastpicid . ".jpg";

    //**insert these lines
    if ($type == 2) {
    rename($ImageName, $newfilename);
    } else {
    if ($type == 1) {
    $image_old = imagecreatefromgif($ImageName);
    } elseif ($type == 3) {
    $image_old = imagecreatefrompng($ImageName);
    }

    //"convert" the image to jpg
    $image_jpg = imagecreatetruecolor($width, $height);
    imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0,
    $width, $height, $width, $height);
    imagejpeg($image_jpg, $newfilename);
    imagedestroy($image_old);
    imagedestroy($image_jpg);
    }

    //**INSERT THESE LINES

    $newthumbname = $ImageThumb . $lastpicid . ".jpg";

    //get the dimensions for the thumbnail
    //$thumb_width = $width * 0.10;
    //$thumb_height = $height * 0.10;
    $thumb_width = 80;
    $thumb_height = 80;


    //create the thumbnail
    $largeimage = imagecreatefromjpeg($newfilename);
    $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
    imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0,
    $thumb_width, $thumb_height, $width, $height);
    imagejpeg($thumb, $newthumbname);
    imagedestroy($largeimage);
    imagedestroy($thumb);
    //**END OF INSERT
    //$url = "location: showimage.php?id=" . $lastpicid;
    //header($url);
    //**end of inserted lines
    echo("<font color = red><b>Image Has been Added Successfully! </b>");

    }
    }

    ?>

    ###############################
     
    salayhin, Jun 5, 2010 IP
  2. Scripts man

    Scripts man Guest

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i want o know
    wht adding the date of img in the database
    why why
    is there is no server to doing that?
    you can just save the files name in the database
    and save the img file in the server
    you can use any thing of these
    http://www.jooria.com/projects/view?project=983
    http://www.jooria.com/projects/view?project=981
    http://www.jooria.com/projects/view?project=980
    http://www.jooria.com/projects/view?project=944
    http://www.jooria.com/projects/view?project=965
    http://www.jooria.com/projects/view?project=982
     
    Scripts man, Jun 5, 2010 IP
  3. salayhin

    salayhin Peon

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello,
    Thanks for your reply.

    I want this automatically to upload in server and ata the same time add data to the database because i want to develop a school management software.

    Please help me

    Thanks
     
    salayhin, Jun 5, 2010 IP
  4. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #4
    Did you make sure the upload folders are set to CH777 and that you GD support enabled on your php setup?
     
    HuggyEssex, Jun 5, 2010 IP
  5. salayhin

    salayhin Peon

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes i have made the 777 permission but still nothing...
     
    salayhin, Jun 5, 2010 IP
  6. shubhamjain

    shubhamjain Active Member

    Messages:
    215
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #6
    Verify that the Upload form declare the "multipart form data" thing.
     
    shubhamjain, Jun 5, 2010 IP
  7. salayhin

    salayhin Peon

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I have done this "multipart form data".
     
    salayhin, Jun 5, 2010 IP
  8. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #8
    Put as MultiForm Data and also CHMOD to 0777 the Target folder and i hope this must be
    like this

     
    roopajyothi, Jun 5, 2010 IP