图片未在我的网站上显示

时间:2015-03-07 22:03:23

标签: php apache laravel

我不想问这样的问题。但是这些图像并没有显示在我的网络服务器上,就像它们在我的本地系统上一样。

PHP信息http://www.classifiedtestbed.com/test.php

缺少图片的示例:http://www.classifiedtestbed.com/advertisements/2

我的脚本是正确的,但我认为这可能是一个apache或php问题,请查看我的phpinfo()并告诉我你是否看错了。

图像应该从我的tmp目录进行处理并移动到我的上传目录但是从未发生过...我在php_errors中没有错误并检查了httd / error_log

任何建议都会非常感谢,谢谢!

public function createTN($image) {
    # Load Zebra Image Library
    require_once public_path().'/uploads/Zebra_Image.php';
    $destinationPath = public_path().'/uploads/thumbnails/';

    $tn = new Zebra_Image();
    $tn->source_path = $image->getRealPath();
    $tn->target_path = $destinationPath.$this->name.'.jpg';
    $tn->jpeg_quality = 60;
    $tn->preserve_aspect_ratio = true;
    $tn->enlarge_smaller_images = true;
    $tn->resize(100, 100, ZEBRA_IMAGE_CROP_CENTER);
}

ps:文件模式已更改为777

PHP Files are not moving from /tmp

新代码

public function createTN($image) {
    # Load Zebra Image Library
    require_once public_path().'/uploads/Zebra_Image.php';
    $destinationPath = public_path().'/uploads/thumbnails/';

    $tn = new Zebra_Image();
    $tn->source_path = $image->getRealPath();
    $tn->target_path = $destinationPath.$this->name.'.jpg';
    $tn->jpeg_quality = 60;
    $tn->preserve_aspect_ratio = true;
    $tn->enlarge_smaller_images = true;

    if (!$tn->resize(100, 100, ZEBRA_IMAGE_CROP_CENTER)) echo 'Error: ' . $tn->error;
    echo 'Is file: ' . is_file($tn->source_path);
    exit;
    /*$tn->resize(100, 100, ZEBRA_IMAGE_CROP_CENTER);*/
}

输出:Error: 7Is file: 1

1 个答案:

答案 0 :(得分:1)

当某些事情发生故障时,您可以逐步调试事物以查看它们是否产生预期结果。所以在你的情况下,这是一个方法$tn->resize(100, 100, ZEBRA_IMAGE_CROP_CENTER);,用于调整图像大小并保存它。

来自zebra的源代码我们有:

 *  @return boolean                         Returns TRUE on success or FALSE on error.
 *
 *                                          If FALSE is returned, check the {@link error} property to see what went
 *                                          wrong
 */
public function resize($width = 0, $height = 0, $method = ZEBRA_IMAGE_CROP_CENTER, $background_color = '#FFFFFF')

如此不经意地,为了找出问题所在,你可以简单地测试它:

if ( ! $tm->resize(..) ){
   switch($tm->error){
      // handle it somehow here
   }
}

至于错误代码的说明,有official page

确保已安装libgd

http://libgd.github.io/

http://php.net/manual/en/book.image.php

CentOS7

  1. yum install gd gd-devel php-gd
  2. 重启apache
相关问题