douhoushou8385 2019-04-18 23:01
浏览 25

如何让我的php文件正确读取这些图像?

I've created this to get the size of several images I have in a directory....

$image = file_get_contents("$fileLocation");
$source = imagecreatefromstring($image);

$width = imagesx($source);
$height = imagesy($source);
echo "   width : ", $width, " $nbsp; height : ", $height, 

When it gets to an image with a name that has a space in the name, it gives me an error....

Warning: imagecreatefromstring(): Data is not in a recognized format in /setupdb.php on line 23

Warning: imagesx() expects parameter 1 to be resource, boolean given in /setupdb.php on line 25

Warning: imagesy() expects parameter 1 to be resource, boolean given in /setupdb.php on line 26

What do I need to add to get it to read them better?

  • 写回答

1条回答 默认 最新

  • douguio0185 2019-04-19 06:29
    关注

    The error is not about spaces in the filename but about unrecognized image formats. Filenames with spaces for supported image formats will work without errors or warnings (Except you are not reading them correctly and complete into the variable $fileLocation but that part is missing in your code!). You can check the supported image formats of your php installation by running var_dump(gd_info());.

    I would suggest to change your code like this to identify all the files that are not supported images in your directory:

    $image = file_get_contents("$fileLocation");
    $source = imagecreatefromstring($image);
    
    if ($source){
        $width = imagesx($source);
        $height = imagesy($source);
        echo "width : " . $width . " height : ". $height;
    } else {
        echo $fileLocation . " is not a recognized image format";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)