Results 1 to 5 of 5

Thread: Upload Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    32

    Upload Problem

    Hi all,

    I'm using the following code to upload an image .....it works fine locally...But on the remote server it doesn't upload the image..

    -------------------------------------------------------------------------------
    //form field name is "images"

    $image = "$images_name";

    $exten = explode(".", $image);
    $exten = strtolower($exten[1]);
    $exten = chop($exten);

    if (($exten == "gif") || ($exten == "jpg") || ($exten == "jpeg"))
    {
    $path = "whats_new/$image";
    move_uploaded_file($images, "$path");

    $sql = "INSERT INTO item (itm_name, description, unit_price, stock, image) VALUES ('$itm_name', '$description', '$unit_price', '$stock', '$image')";
    $res = mysql_query($sql);

    header("location:add_itm.php?msg=add");
    }
    else
    {
    echo "Wrong extension";
    }
    -----------------------------------------------------------------------------

    Kindly check whats wrong..

    Thanks
    FmKing

    ***************************
    Sharing Knowledge = Good Deed
    ***************************

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    It would help to know what, if any, error your receive. If you don't receive an error, can you explain what happens?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    32
    Thank you for replying,

    When i submit....The name of the file goes to the database but not the image on the remote server.....

    It seems to me that there is something wrong in the path.

    What exactly should the path be....i'm using
    $path = "whats_new/$image";


    Thanks
    FmKing

    ***************************
    Sharing Knowledge = Good Deed
    ***************************

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Try using the absolute path to your folder:

    Code:
    $path = "/home/your_site/public_html/whats_new/$image";
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You also might want to try this:

    Code:
    $res = move_uploaded_file($images, "$path");
    
    if ($res === false) {
        die("Invalid upload file!");
    }
    That way you can make sure the upload file is valid. Also, where are you getting $images from?

    Is that a global form variable? If so, that's a big no-no.

    Try using:

    Code:
    $res = move_uploaded_file($_FILES['images']['name'], "$path");
    
    if ($res === false) {
        die("Invalid upload file!");
    }
    Assuming $images was a form variable.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width