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

エラーメッセージ

目次一覧

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

エラー修正例 1


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

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

 閲覧数:24 投稿日: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
2024/4/28 12:43 更新
週間人気ページランキング / 4-21 → 4-27
順位 ページタイトル抜粋 アクセス数
1 Parse error: syntax error, unexpected 'public' (T_PUBLIC) | Parse error(エラーメッセージ) 13
2 ブラウザを閉じたらセッションデータはどうなるの? | セッション 11
3 curl で Cookie を使用する 7
4 PHPで定数を定義する方法は2種類ある / 配列定数の定義 6
5 Composer | 依存関係マネージャ 5
6 コード例 … 「例外処理」はネストすることができる 4
6 Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△ | Warning(エラーメッセージ) 4
6 ブラウザを閉じたらセッションデータはどうなるの? | セッション 4
7 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined | Fatal error(エラーメッセージ) 3
7 Fatal error: Uncaught Error: Call to a member function modify() on string | Fatal error(エラーメッセージ) 3
7 Fatal error: Access level to ▲::$△ must be protected (as in class ●) or weaker | Fatal error(エラーメッセージ) 3
8 or(||) | 演算子 2
8 セッション カテゴリー 2
8 関数 2
8 セッション管理が必要な理由は、HTTPプロトコルには状態を保持する機能がないため | セッション 2
8 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'カラム名' cannot be null | Fatal error(エラーメッセージ) 2
8 T_CONSTANT_ENCAPSED_STRING | エラーメッセージ 2
8 セッション名 | セッション 2
8 例外処理 | 制御構造 2
8 register_shutdown_function | 関数処理 関数 2
2024/4/28 1:01 更新