LoginSignup
3
1

More than 5 years have passed since last update.

phpでパスが通らなくなるという事例(php5.6とphp7の違い?php.iniの違い?)

Posted at

getimagesize()の引数に持ってくるパスが
/wp-content/uploads/2017/12/example-400x300.jpgのように
最初に/が入っていると通らなくなった。

エラーが出た環境は以下

exampleサーバ
Php 7.0.18

対応方法

以下のように変更したら解消した。

// 画像のサイズを取得
list($width, $height, $type, $attr) = getimagesize($srcval[1]);

//最初のスラッシュをとる
$img_path = ltrim($srcval[1], '/');
// 画像のサイズを取得
list($width, $height, $type, $attr) = getimagesize($img_path);

exampleサーバ2では以下でもOKだった

/wp-content/uploads/2017/12/example400x300.jpg
Php5.6.32 CGIモード

原因の予想

・phpのバージョン違いによる関数の挙動変更が原因の可能性。
 http://php.net/manual/ja/function.getimagesize.php
 http://php.net/manual/ja/migration70.php
 上記ざっと確認するもそれらしき記述を見つけられませんでした。

・php.iniによるパス解釈の違いがあるとのことでサーバの設定による違いが原因という可能性。
 https://qiita.com/Mizumon/items/6097cbf7082d05f9a550

以下調査結果
exampleサーバ
include_path .:/opt/php-7.0.18/data/pear .:/opt/php-7.0.18/data/pear

example2サーバ Local Value Master Value
include_path .:/usr/local/php/5.6/lib/php .:/usr/local/php/5.6/lib/php

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1