Php 回显图像的文件名

Php 回显图像的文件名,php,curl,Php,Curl,看来简单的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 = $

看来简单的
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;
}
?>

这是我插入的
echo$image希望它至少显示图像的文件名,但它没有

echo basename($image->source);

这将实现技巧

$image
是一个对象,如果您希望回显一个对象,则类必须定义
\u toString
方法

在类中,文件名似乎存储在
$this->source
中。因此,您可能需要考虑在类中添加一个SytoToSs方法,类似于以下内容:

public function __toString()
{
    return $this->source;
}
添加此项后,您将能够执行
echo$image
,并且它将回显
\u toString
返回的任何内容