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

エラーメッセージ

目次一覧

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

エラー修正例 1


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

 閲覧数:240 投稿日: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

 閲覧数:250 投稿日: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
2026/8/24 2:34 更新
週間人気ページランキング / 8-16 → 8-22
順位 ページタイトル抜粋 アクセス数
1 PHP用語 16
2 実際に遭遇した例1. 6
3 定数 3
4 SQLインジェクション | セキュリティ 2
4 _FILE__ | 定数 2
4 P … 親クラスインスタンス生成。親クラス内での$this 2
4 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 23 Out of resources when opening file '/tmp/#sql_2dd6_0.MYI' (Errcode: 24)' | エラーメッセージ 2
4 set_error_handler | 例外処理(制御構造) 2
4 セッションのガベージコレクション (ごみの収集)はなぜ必要なの? 2
4 ( ! ) Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in ★★★ headless-chromium-php/vendor/wrench/wrench/lib/Wrench/Protocol/Protocol.php | エラーメッセージ 2
4 PHPにおけるメソッドのオーバーライドについて /「引数の数や型は、親クラスのメソッドと完全に一致していなければなりません。」とは具体的にどういう意味ですか? 2
5 popen | ファイルシステム (関数) 1
5 エラーメッセージ / エラー原因 / 遭遇例 1 1
5 タイプヒンティング | クラスとオブジェクト 1
5 エラー | 例外処理(制御構造) 1
5 メタキャラクタ 1
5 PHPで定数を定義する方法は2種類ある / 配列定数の定義 1
5 Fatal error: require_once(): Failed opening required 'PEAR.php' | Fatal error(エラーメッセージ) 1
5 __toString()メソッド 1
5 マジックメソッド(クラスとオブジェクト) カテゴリー 1
2026/8/23 5:05 更新