( ! ) Warning: file_put_contents(/a/b.jpg): failed to open stream: No such file or directory in

エラーメッセージ

目次一覧

 状態:-  閲覧数:500  投稿日:2023-12-21  更新日:2023-12-21  
エラーメッセージ / エラー原因 / エラー対応

エラー修正例 1


エラーメッセージ / エラー原因 / エラー対応

 閲覧数:180 投稿日:2023-12-21 更新日:2023-12-21 

エラーメッセージ


( ! ) Warning: file_put_contents(/img/tmp/download.jpg): failed to open stream: No such file or directory in /var/www/html/★★★★/include/post-to-twitter.php on line 74

エラー原因


画像を保存するパスが適切ではない
このエラーは、file_put_contentsが指定されたファイルパスに書き込むことができないときに発生します。
エラーメッセージによれば、指定されたパス/var/www/html/★★★★/include/post-to-twitter.phpに対応するディレクトリが存在しない可能性があります。

エラー対応


画像を保存するパスを適切にする

エラー修正例 1

 閲覧数:177 投稿日:2023-12-21 更新日:2023-12-21 

エラー修正例 1


修正前
$tmpImg = file_get_contents($topicDBAry['img_srcurl']);
$downloadImgPath = dirname(__FILE__).'/img/tmp/download.jpg';
file_put_contents($downloadImgPath,$tmpImg);


保存先のパスが'/var/www/html/★★★★/include/../tmp/img/download.jpg'となることが原因だと思われるが、保存先のパスを'/var/www/html/★★★★/tmp/img/download.jpg'とするためにはPHPをどう書けばよいか?

修正後
指定された保存先のパスを修正するには、dirname(__FILE__) を使用している部分を修正すれば良い
$tmpImg = file_get_contents($topicDBAry['img_srcurl']);
$downloadImgPath = dirname(__FILE__).'/../tmp/img/download.jpg';
$downloadImgPath = realpath($downloadImgPath);
file_put_contents($downloadImgPath,$tmpImg);


この修正では、realpath() 関数を使用して、指定されたパスを絶対パスに変換しています。
これにより、'/../tmp/img/download.jpg' の相対パスが正しい絶対パスに解決されます。
修正後、$downloadImgPath には正しい絶対パスが格納され、ファイルの保存が成功します。


( ! ) Warning: Declaration of xxxx should be compatible with

( ! ) Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in ★★★ headless-chromium-php/vendor/wrench/wrench/lib/Wrench/Protocol/Protocol.php

コメント投稿(ログインが必要)



類似度ページランキング
順位 ページタイトル抜粋
1 ( ! ) Warning: file_put_contents(/a/b.jpg): failed to open stream: No such file or directory in 32
2 ( ! ) Warning: Declaration of xxxx should be compatible with 31
3 Warning: include(**.php) [function.include]: failed to open stream: No such file 27
4 Warning: array_rand() [function.array-rand]: Second argument has to be between 1 27
5 Fatal error: Uncaught Error: Call to a member function modify() on string 26
6 Parse error: syntax error, unexpected 'public' (T_PUBLIC) 26
7 Fatal error: require_once(): Failed opening required 'XML/RSS.php' 26
8 Parse error: syntax error, unexpected 'new' (T_NEW) 26
9 SHA-1(Secure Hash Algorithm 1) 26
10 Fatal error: Uncaught Error: Call to undefined function bcsub() 25
11 Fatal error: require_once(): Failed opening required 'PEAR.php' 25
12 #1016 - Can't open file: './database_name/#sql-38f_36aa.frm' (errno: 24) 25
13 Warning: include() [function.include]: Failed opening '**.php' for inclusion (in 25
14 Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 25
15 Fatal error: Function name must be a string in /○○.php on line △△ 25
16 Fatal error: Uncaught Error: Class 'Mecab_Tagger' not found in /var/www/ 25
17 Warning: mb_convert_encoding(): Unable to detect character encoding 25
18 Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△ 25
19 #1548 - Cannot load from mysql.proc. The table is probably corrupted 25
20 ( ! ) Fatal error: Uncaught Abraham\TwitterOAuth\TwitterOAuthException 24
2025/9/16 2:18 更新
週間人気ページランキング / 9-9 → 9-15
順位 ページタイトル抜粋 アクセス数
1 session_start() | セッション 8
2 定数 7
3 「POSIX正規表現」と「PCRE正規表現」の違い 5
4 ob紛らわしい関数()一覧 | 出力バッファリング制御(関数) 4
4 演算子 カテゴリー 4
5 コード例 … 「例外処理」はネストすることができる 3
5 Fatal error: Using $this when not in object context in /○○.php on line △△ | Fatal error(エラーメッセージ) 3
5 Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△ | Warning(エラーメッセージ) 3
5 Warning: include() [function.include]: Failed opening '**.php' for inclusion (in | Warning(エラーメッセージ) 3
5 http_build_query | URLs(関数) 3
5 Parse error: syntax error, unexpected 'public' (T_PUBLIC) | Parse error(エラーメッセージ) 3
5 Fatal error: Access level to ▲::$△ must be protected (as in class ●) or weaker | Fatal error(エラーメッセージ) 3
5 スコープ | 変数 3
6 オブジェクト | クラスとオブジェクト 2
6 Fatal error: Call to undefined method MDB2_Error::execute() in ○○ on line △△ | Fatal error(エラーメッセージ) 2
6 PHPで定数を定義する方法は2種類ある / 配列定数の定義 2
6 htmlspecialchars / htmlentities / addslashes / mysql_real_escape_string / mysqli_real_escape_string | セキュリティ 2
6 セッション管理が必要な理由は、HTTPプロトコルには状態を保持する機能がないため | セッション 2
6 Trying to get property of non-object  | Notice(エラーメッセージ) 2
6 Fatal error(エラーメッセージ) カテゴリー 2
2025/9/16 1:01 更新