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');
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.
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.
I don't know what is the problem in your codes. Yet you can try with something different. I have used it in my site. Check this file: http://www.3wlead.com/tools/image_upload.rar
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