php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27851 fopen , fread or fwrite bug
Submitted: 2004-04-03 04:10 UTC Modified: 2004-04-03 07:19 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: publicfreedom at yahoo dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.4 OS: RedHat Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: publicfreedom at yahoo dot com
New email:
PHP Version: OS:

 

 [2004-04-03 04:10 UTC] publicfreedom at yahoo dot com
Description:
------------
Hello,
I have a php program that reads a file from a given URL and then recreates it on my server host using fopen, fread and fwrite. The program was running perfectly with php version 4.2.3 for the last 9 months, then when my hosting provider upgraded to php version 4.3.4 it produced the following bug:
When the file URL is recreated it is sometimes not complete, i.e the number of bytes of the new recreated file is less than the original file which results in an incompleted or corrupted file. I reported my hosting provider with the bug, but they told me to contact php.net . Is there a fix for that? Please help. Here is a link to the part of the program that is not working. I have illustrated it clearly.
http://ssviewpoint.com/filetest/index.php

Thank you.


Reproduce code:
---------------
<?
$fileurl ='http://www.google.com/intl/en_ALL/images/images_hp.gif';
 $fd =fopen ($fileurl,"rb");
 if (!$fd){
   echo "<p><br>Unable to open remote file.<br> Name : <b>$fileurl<b>";
   exit;
 } //if $fd

 $fs=8388608;  //1Mb = 1048576   -  now fs is 80 Mb
 $contents =fread ($fd,$fs);
 fclose ($fd);
//Now the binary contents of file is in $contents
 $newfilename=  'googlefile.gif'; 
 $fdffp =fopen($newfilename,"w");
 fwrite($fdffp,$contents);
 fclose($fdffp);
 $thesize= filesize($newfilename);


//$newfilename should be an identical copy of $fileurl and $thesize should be its size but it is not.
?>

Expected result:
----------------
I expect to find an identical file of the file in the given URL, created on my host.

Actual result:
--------------
The new created file is less in size than the actual size which results in a corrupted file.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-03 05:50 UTC] publicfreedom at yahoo dot com
Hello again,
I found the solution on this link 
http://bugs.php.net/bug.php?id=24001&edit=2

I tested it and it worked, I am just wandering why or how the function was working on the previous php version(4.2.3)!
Thank you to all supporters.
 [2004-04-03 07:19 UTC] derick@php.net
We have some new semantics in reading from files; but the old way was never really "supported" like you were doing. It's not a bug -> bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 26 11:01:30 2024 UTC