Image Upload Problem

Discussion in 'PHP' started by nile1483, Mar 8, 2007.

  1. #1
    I am trying to upload image but there are some proble image can`t upload on server, record upload in databse but image can`t upload

    Here is code

    <?
    ob_start();
    session_start();

    if(!isset($_SESSION['isadmin']) || $_SESSION['isadmin'] != 1) {
    header('Location: index.php');
    exit;
    }

    include_once("../lib/config.php");
    include_once("../lib/dbclass.php");
    include_once("../lib/functions.php");

    $pid = (isset($_REQUEST['pid']) && !empty($_REQUEST['pid']))? $_REQUEST['pid'] : '';
    $mode = (isset($_REQUEST['mode']) && !empty($_REQUEST['mode']))? $_REQUEST['mode'] : 'add';
    $mode = strtolower($mode);
    $productdetail = $_REQUEST['productdetail'];

    if(isset($_FILES['productimage']) && $_FILES['productimage']['size'] != 0)
    {

    $imagename = time()."_".$_FILES['productimage']['name'];
    $uploadfile = PRODUCT_PIC_PATH. "/".$imagename;
    $uploadResult = move_uploaded_file($_FILES['productimage']['tmp_name'], $uploadfile);
    $productdetail[pimage] = $imagename;
    }

    $dbObj = new dbclass;

    if($mode == 'add') {

    $productQuery = "SELECT MAX(porder) as porder FROM `products` ";
    $productResult = $dbObj->select($productQuery);
    $porder = $productResult[0]['porder'] + 1;
    $productdetail['porder'] = $porder;

    $pid = add_record($dbObj, 'products', $productdetail);
    $errorMessage = rawurlencode('Product information added successfully');
     
    nile1483, Mar 8, 2007 IP
  2. php_daemon

    php_daemon Active Member

    Messages:
    34
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #2
    Check $_FILES['productimage']['error'] against php.net/manual/en/features.file-upload.errors.php to find out what the error is.

    Sorry for the link, they won't let me post live links yet. :)
     
    php_daemon, Mar 8, 2007 IP
  3. nile1483

    nile1483 Active Member

    Messages:
    345
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #3
    There are no error, but image can`t upload at destination

     
    nile1483, Mar 8, 2007 IP
  4. php_daemon

    php_daemon Active Member

    Messages:
    34
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #4
    You mean $_FILES['productimage']['error'] is 0?

    I can see your script fails silently in case of a failed upload. That means you won't see any error messages from your script. But that doesn't mean everything goes right.

    Add
    
    echo "Error=".$_FILES['productimage']['error'];
    
    PHP:
    just before
    if(isset($_FILES['productimage']) && $_FILES['productimage']['size'] != 0)
    
    PHP:
    and see what error code does it display. From there it's easy to track the problem.
     
    php_daemon, Mar 8, 2007 IP
  5. nile1483

    nile1483 Active Member

    Messages:
    345
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #5
    i change it but there are steel no error
     
    nile1483, Mar 9, 2007 IP
  6. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #6
    srobona, Mar 9, 2007 IP
  7. nile1483

    nile1483 Active Member

    Messages:
    345
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #7
    nile1483, Mar 9, 2007 IP
  8. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #8
    image uploading code. The thumbnail will be saved in db and the main image in folder. Try and if you get help, please let me know :)
     
    srobona, Mar 9, 2007 IP