回显图像的文件名
看来简单的 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;
希望它能够至少显示图像的文件名,但事实并非如此。
It seems the simple echo $image
doesn't do the trick for this one:
<?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;
}
?>
Here's class.get.image.php You see i've inserted echo $image;
hoping it would display at least the filename of the image but it doesn't.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样就可以了
that will do the trick
$image
是一个对象,如果您希望回显对象,该类必须定义__toString
方法。在您的类中,文件名似乎存储在
$this->source
中。因此,您可能需要考虑向您的类添加类似于以下内容的__toString
方法:添加此方法后,您将能够执行
echo $image
,并且它会回显__toString
返回的任何内容。$image
is an object, and if you wish to echo an object, the class must define the__toString
method.In your class, it looks like the filename is stored in
$this->source
. Therefore you might want to consider adding a__toString
method to your class that is similar to the following:After you add this, you will be able to do
echo $image
, and it will echo whatever__toString
returns.