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

エラーメッセージ

目次一覧

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

エラー修正例 1


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

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

 閲覧数:169 投稿日: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/8/28 17:21 更新
週間人気ページランキング / 8-21 → 8-27
順位 ページタイトル抜粋 アクセス数
1 PHPで定数を定義する方法は2種類ある / 配列定数の定義 6
2 ブラウザを閉じたらセッションデータはどうなるの? | セッション 4
2 対応例1.メモリ不足なので、PHPの最大使用メモリを増加するよう変更 4
3 http_build_queryとは? / 構文 /パラメータ 3
3 Fatal error: Access level to ▲::$△ must be protected (as in class ●) or weaker | Fatal error(エラーメッセージ) 3
3 定数 3
4 session.hash_function | セッション 2
4 Parse error: syntax error, unexpected 'public' (T_PUBLIC) | Parse error(エラーメッセージ) 2
4 「include_once」で「An error occurred.」と表示される場合の原因は、大きく分けると 2 種類あります。 | エラーメッセージ 2
4 htmlspecialchars / htmlentities / addslashes / mysql_real_escape_string / mysqli_real_escape_string | セキュリティ 2
4 Fatal error: require_once(): Failed opening required 'PEAR.php' | Fatal error(エラーメッセージ) 2
4 dirname() / (__FILE__ ) / basename( dirname( __FILE__ ) ); | 関数 2
4 PHPにおけるメソッドのオーバーライドについて /「引数の数や型は、親クラスのメソッドと完全に一致していなければなりません。」とは具体的にどういう意味ですか? 2
5 spliceImageメソッド | Imagickクラス 1
5 エラー | 例外処理(制御構造) 1
5 Parse error: syntax error, unexpected T_REQUIRE_ONCE, expecting T_FUNCTION | Parse error(エラーメッセージ) 1
5 リファレンスを返す | リファレンス 1
5 セッション・ハイジャック | セキュリティ 1
5 エラーメッセージ / エラー原因 / エラー対応 1
5 Composer | 依存関係マネージャ 1
2025/8/28 1:01 更新