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

エラーメッセージ

目次一覧

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

エラー修正例 1


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

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

 閲覧数:107 投稿日: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/2/06 5:37 更新
週間人気ページランキング / 1-30 → 2-5
順位 ページタイトル抜粋 アクセス数
1 Parse error: syntax error, unexpected 'public' (T_PUBLIC) | Parse error(エラーメッセージ) 10
2 ブラウザを閉じたらセッションデータはどうなるの? | セッション 9
3 curl で Cookie を使用する 4
3 Fatal error: Access level to ▲::$△ must be protected (as in class ●) or weaker | Fatal error(エラーメッセージ) 4
3 PHPで定数を定義する方法は2種類ある / 配列定数の定義 4
4 コード例 … 「例外処理」はネストすることができる 3
4 Warning: PDO::query(): LOAD DATA LOCAL INFILE forbidden | Warning(エラーメッセージ) 3
4 http_build_queryとは? / 構文 /パラメータ 3
4 Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | エラーメッセージ 3
5 Fatal error: Cannot redeclare 関数名() (previously declared in ファイル名:○○) in ファイル名 | Fatal error(エラーメッセージ) 2
5 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'データベースユーザー名'@'localhost' (using password: YES)' | phpMyAdmin(データベース関連) 2
5 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined | Fatal error(エラーメッセージ) 2
5 new clone違い | 演算子 2
5 オブジェクト関係マッピング | データベース関連 2
5 array_filter | 配列 2
6 Fatal error: Uncaught Error: Call to a member function modify() on string | Fatal error(エラーメッセージ) 1
6 Fatal error: require_once(): Failed opening required 'PEAR.php' | Fatal error(エラーメッセージ) 1
6 セッション単位 | セッション 1
6 htmlspecialchars / htmlentities / addslashes / mysql_real_escape_string / mysqli_real_escape_string | セキュリティ 1
6 dirname() / (__FILE__ ) / basename( dirname( __FILE__ ) ); | 関数 1
2025/2/6 1:02 更新