dowaw80220 2015-01-15 04:32
浏览 179

使用imagecreatefromjpeg()函数时,会出现“文件名不能为空”

I have a code to upload an image, then creates thumbnail on the fly for this uploaded image.

The following code that creates the thumbnail (thumb.php).

$fileName = filter_input(INPUT_GET, 'src');
$width = filter_input(INPUT_GET, 'width', FILTER_SANITIZE_NUMBER_INT);
$height = filter_input(INPUT_GET, 'height', FILTER_SANITIZE_NUMBER_INT);

$im = imagecreatefromjpeg($fileName); //<=== the error message indicates to this line
$tmp_im = imagecreatetruecolor($width, $height);
$imWidth = imagesx($im);
$imHeight = imagesy($im);
imagecopyresampled($tmp_im, $im, 0, 0, 0, 0, $width, $height, $imWidth, $imHeight);
header("Content-type: image/jpeg");
imagejpeg($tmp_im);
imagedestroy($im);
imagedestroy($tmp_im);

The following code that upload the image, then implement the creation of thumbnail for the uploaded image, then display this thumbnail.

require_once ('thumb.php');

$image_dir = "images/";
if($_FILES['photo']['error'] == 0){  
    $fileUPloaded = $_FILES['photo']['name'];
    move_uploaded_file($_FILES['photo']['tmp_name'], $image_dir.$fileUPloaded);
    echo "<a href='".$image_dir.$fileUPloaded."'><img src='thumb.php?src=".$image_dir.$fileUPloaded."&width=350&height=250' alt='' /></a>";
}

Now, why appears an error Warning: imagecreatefromjpeg(): Filename cannot be empty.

Note that the image is uploaded, and was created thumbnail for uploaded image, and was displayed thumbnail. so, why that error message appear ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥170 如图所示配置eNSP
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果
    • ¥15 键盘指令混乱情况下的启动盘系统重装