note 47110 added to function.fpassthru
| From: | phpnet at -remove-me-uchange dot co dot uk | Date: | Wed, 03 Nov 2004 13:11:15 +0000 |
| Subject: | note 47110 added to function.fpassthru | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-79542@lists.php.net to get a copy of this message | ||
I've modified the example given by straz at -removethispart-mac dot com to count each byte of
the file out. This can then be compared with the filesize once the file sending is complete to
determine whether the file was sent succesfully or not.
Of course, this doesn't guarantee that the user actually recieved the file successfully though
will let us know if something goes wrong half way through reading/sending the file at our end.
<?
/* fpassthru is apparantly a memory-hog. Use this instead */
while(!feof($fp)) {
$buf = fread($fp, 4096);
echo $buf;
$bytesSent+=strlen($buf); /* We know how many bytes were sent to the user */
}
?>
I've then got this code to update my database to say that the file was downloaded successfully.
<?
if($bytesSent==filesize($file)) {
/* Do some cool stuff here! */
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.fpassthru.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47110
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47110&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47110&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47110&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47110&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47110&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47110&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47110&report=yes
Search -- http://master.php.net/manage/user-notes.php