php
  • curl
  • 2011-09-19 21 views -1 likes 
    -1

    似乎簡單echo $image不爲這一個做的伎倆:回聲圖像的文件名

    <?php 
    include_once 'class.get.image.php'; 
    
    // initialize the class 
    $image = new GetImage; 
    
    // just an image URL 
    $image->source = $_POST["url"]; 
    $image->save_to = 'images/'; // with trailing slash at the end 
    $get = $image->download('curl'); // using GD 
    
    if($get) 
    { 
        echo 'The image has been saved.'; 
        echo $image; 
    } 
    ?> 
    

    這裏的class.get.image.php你知道我插入echo $image;希望它會顯示至少的文件名圖像但它沒有。

    回答

    2
    echo basename($image->source); 
    

    ,會做的伎倆

    +1

    你救了我!謝謝 – Zhianc

    0

    $image是一個對象,如果你想重複一個對象,類必須定義__toString方法。

    在你的課上,它看起來像文件名存儲在$this->source。因此,你可能要考慮增加一個__toString方法類是類似於以下內容:

    public function __toString() 
    { 
        return $this->source; 
    } 
    

    添加此之後,你就可以做echo $image,它會響應任何__toString回報。

    相關問題