图片未显示在我的网站上
Images not showing on my site
我讨厌问这种问题。但是图像在我的网络服务器上显示时不像在我的本地系统上那样显示。
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
新代码
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
当某事失败时,您可以简单地逐步调试,看看它们是否产生预期的结果。因此,在您的情况下,这是一种方法 $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://php.net/manual/en/book.image.php
CentOS7
yum install gd gd-devel php-gd
- 重启apache
我讨厌问这种问题。但是图像在我的网络服务器上显示时不像在我的本地系统上那样显示。
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
新代码
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
当某事失败时,您可以简单地逐步调试,看看它们是否产生预期的结果。因此,在您的情况下,这是一种方法 $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://php.net/manual/en/book.image.php
CentOS7
yum install gd gd-devel php-gd
- 重启apache