note 125653 added to function.file-put-contents
| From: | jul dot rosset at gmail dot com | Date: | Mon, 04 Jan 2021 15:56:38 +0000 |
| Subject: | note 125653 added to function.file-put-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216060@lists.php.net to get a copy of this message | ||
This function doesn't return False if all data isn't write, especially when data is a
stream resource
You must check yourself using return value.
<?php
$url = 'https://monsite.fr/image.png';
$size = filesize($url);
$written = file_put_contents('image.png', fopen($url, 'r'));
if ($size === false || $size != $written) {
die('Download failed');
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.159.165 (proxied: 217.128.76.173)
----
Manual Page -- http://php.net/manual/en/function.file-put-contents.php
Edit -- https://master.php.net/note/edit/125653
Del: integrated -- https://master.php.net/note/delete/125653/integrated
Del: useless -- https://master.php.net/note/delete/125653/useless
Del: bad code -- https://master.php.net/note/delete/125653/bad+code
Del: spam -- https://master.php.net/note/delete/125653/spam
Del: non-english -- https://master.php.net/note/delete/125653/non-english
Del: in docs -- https://master.php.net/note/delete/125653/in+docs
Del: other reasons-- https://master.php.net/note/delete/125653
Reject -- https://master.php.net/note/reject/125653
Search -- https://master.php.net/manage/user-notes.php