Current location: Hot Scripts Forums » Programming Languages » PHP » print_r not working here


print_r not working here

Reply
  #1 (permalink)  
Old 09-20-09, 06:16 AM
karthikanov24 karthikanov24 is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
print_r not working here

hi

In the following php funtion code, function uploadproductimage() returns an array to $images variable in funtion addproduct().


If i use print_r ($images);
or print_r($images['image']); etc..

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..
why is to so? Could u give me the reason?

PHP Code:

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 $imagePathMAX_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 $thumbnailPathTHUMBNAIL_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

Last edited by Nico; 09-20-09 at 06:25 AM. Reason: Please use [php] wrappers for PHP code.
Reply With Quote
  #2 (permalink)  
Old 09-20-09, 09:21 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Go to PHP: Hypertext Preprocessor and read the pages that describe echo and print_r.
Reply With Quote
  #3 (permalink)  
Old 09-21-09, 07:59 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
print_r() just output some human-readable info about a variable, it's not really intended to be part of a function or to be used programatically. It's more for debugging and as an aid in visualizing array structures.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #4 (permalink)  
Old 09-21-09, 10:44 AM
karthikanov24 karthikanov24 is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
thanks!

thanks a lot to all of you...i understood!
Reply With Quote
  #5 (permalink)  
Old 09-21-09, 04:32 PM
GameFrame GameFrame is offline
Newbie Coder
 
Join Date: May 2009
Location: Finland
Posts: 35
Thanks: 0
Thanked 3 Times in 3 Posts
print_r() is actually for debugging out arrays or global variables. Like this way: print_r($_POST);

echo will not work with arrays. Now you should have even better picture
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Make Rewrite Modul Working in Windows, cause .htaccess ist not working specialex Web Servers 5 04-09-08 11:07 AM
JS script not working properly on IE but working on Firefox!!! sujata_ghosh JavaScript 4 05-21-07 05:46 AM
Form with Photo Upload not working HELP ! mckenzie ASP 1 11-02-06 02:46 PM
ASP not working in IIS5 on WinXP Pro cistate ASP 5 06-18-04 02:31 PM
HTTP_REFERER not working Kaikki ASP 6 02-22-04 02:38 PM


All times are GMT -5. The time now is 07:59 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.