karthikanov24 Posted September 20, 2009 Share Posted September 20, 2009 hi In the following php funtion code, function uploadproductimage() returns an array at line 77 of the below posting, to $images variable at line 10 in funtion addproduct(). If i use print_r ($images); or print_r($images['image']); etc.. (As we know that arrays should be printed using print_r) below the line of code in addproduct() as follows: $images = uploadProductImage('fleImage', SRV_ROOT . 'images/product/'); print_r($images) instead,if i use ,echo $image; i get the output of $image variable.. Could u give me the reason,please? <?php function addProduct() { $catId = $_POST['cboCategory']; $name = $_POST['txtName']; $description = $_POST['mtxDescription']; $price = str_replace(',', '', (double)$_POST['txtPrice']); $qty = (int)$_POST['txtQty']; $images = uploadProductImage('fleImage', SRV_ROOT . 'images/product/'); $mainImage = $images['image']; $thumbnail = $images['thumbnail']; $sql = "INSERT INTO tbl_product (cat_id, pd_name, pd_description, pd_price, pd_qty, pd_image, pd_thumbnail, pd_date) VALUES ('$catId', '$name', '$description', $price, $qty, '$mainImage', '$thumbnail', NOW())"; $result = dbQuery($sql); header("Location: index.php?catId=$catId"); } /* Upload an image and return the uploaded image name */ function uploadProductImage($inputName, $uploadDir) { $image = $_FILES[$inputName]; $imagePath = ''; $thumbnailPath = ''; // if a file is given if (trim($image['tmp_name']) != '') { $ext = substr(strrchr($image['name'], "."), 1); //$extensions[$image['type']]; // generate a random new file name to avoid name conflict $imagePath = md5(rand() * time()) . ".$ext"; list($width, $height, $type, $attr) = getimagesize($image['tmp_name']); // make sure the image width does not exceed the // maximum allowed width if (LIMIT_PRODUCT_WIDTH && $width > MAX_PRODUCT_IMAGE_WIDTH) { $result = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_PRODUCT_IMAGE_WIDTH); $imagePath = $result; } else { $result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath); } if ($result) { // create thumbnail $thumbnailPath = md5(rand() * time()) . ".$ext"; $result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, THUMBNAIL_WIDTH); // create thumbnail failed, delete the image if (!$result) { unlink($uploadDir . $imagePath); $imagePath = $thumbnailPath = ''; } else { $thumbnailPath = $result; } } else { // the product cannot be upload / resized $imagePath = $thumbnailPath = ''; } } return array('image' => $imagePath, 'thumbnail' => $thumbnailPath); } ?> Thanks, karthikanov24 Quote Link to comment Share on other sites More sharing options...
MadTechie Posted September 20, 2009 Share Posted September 20, 2009 Nothing wrong, the print_r ($images); works fine Quote Link to comment Share on other sites More sharing options...
khr2003 Posted September 21, 2009 Share Posted September 21, 2009 Frankly I did not understand your question 100%, but I think the print_r is working fine, maybe you forgot to add ; at the end of print_r function. One hint though: a single array element can not be printed using print_r. Instead you might want to use echo $images['image']; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.