電子書籍の厳選無料作品が豊富!

サイトにWarning: preg_match_allのようなエラーが出ており、困っているので解決方法を教えて
いただきたいです。
Warning: preg_match_all() expects parameter 2 to be string, array given in /home/サーバー名/サイト名/public_html/wp-includes/functions.php on line 4264

Warning: strpos() expects parameter 1 to be string, array given in /home/サーバー名/サイト名/public_html/wp-includes/functions.php on line 4269

Warning: mb_substr() expects parameter 1 to be string, array given in/home/サーバー名/サイト名/public_html/wp-includes/functions.php on line 4269

このようなエラーが存在しています。

4264行目から4271行目までがこちらになります。

if ( preg_match_all( '#\.\./#', $file, $matches, PREG_SET_ORDER )&& ( count( $matches ) > 1 ) ) {
return 1;
}

// `../` which does not occur at the end of the path is not allowed:
if ( false !== strpos( $file, '../' ) && '../' !== mb_substr( $file, -3, 3 ) ) {
return 1;
}

なお、phpなど全然触ったことがないために
解決方法などを教えていただけるとありがたいです。

A 回答 (2件)

wordpressですね。



ソースを見る限り、変数 $file にはファイル名が入らなければいけないけれど、別の値が入ってしまっている。
そしてその値が配列だからエラーが出ている。
かな。

【正】$file = "file_name.jpg";
【誤】$file = array('hoge', 'haystack');

var_dump($file); exit;
してみましょう。変数 $file に何の値が入っているのかわかります。ファイル名が入っていなかったら、代入部分を見直しましょう。

と、言ってはみましたが、PHP触った事がないのであればソースをいじったりはしてない??

もしそうなら、バージョンと合わないプラグインでも入れたか、ファイル選択時に許容されていないファイル形式を選択したか。ですかね。
    • good
    • 0

あなたが挙げられた warnig はいずれも「関数の n 番目の引数は string 型を期待しているが、実際には配列が渡されている」という意味です。


で、問題の引数にはいずれも変数 $file が渡されています。この変数の中身が問題でしょうが……。

残念ながらあなたが提示されたソースファイルだけでは $file に対してどのような代入をしているのかがわかりません。
$file に代入している個所 ±10 行ほどの提示をお願いします。

ただし、
> なお、phpなど全然触ったことがないために
> 解決方法などを教えていただけるとありがたいです。
とおっしゃるならば、身近にいる PHP の知識のある知り合いに直接コード全文を見せた方が早いと思われます。
……というか、なぜ 4000 行以上ある PHP コードを「全然触ったことがない」というあなたが担当することになったのでしょうか?
    • good
    • 0
この回答へのお礼

@param string $file File path.
* @param array $allowed_files Optional. List of allowed files.
* @return int 0 means nothing is wrong, greater than 0 means something was wrong.
*/
function validate_file( $file, $allowed_files = array() ) {
// `../` on its own is not allowed:
if ( '../' === $file ) {
return 1;
}

// More than one occurence of `../` is not allowed:
if ( preg_match_all( '#\.\./#', $file, $matches, PREG_SET_ORDER ) && ( count( $matches ) > 1 ) ) {
return 1;
}

// `../` which does not occur at the end of the path is not allowed:
if ( false !== strpos( $file, '../' ) && '../' !== mb_substr( $file, -3, 3 ) ) {
return 1;
}

// Files not in the allowed file list are not allowed:
if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) )
return 3;

// Absolute Windows drive paths are not allowed:
if (':' == substr( $file, 1, 1 ) )
return 2;

return 0;
}
回答ありがとうございます。
こちらをみてわかりますでしょうか?
趣味でブログをやり始めたのですが、
このよう行が普通なのかと思っておりました。

お礼日時:2018/03/05 23:26

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!