php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65701 filesize() returns wrong result after copy
Submitted: 2013-09-18 17:51 UTC Modified: 2014-04-14 02:23 UTC
From: flack at contentcontrol-berlin dot de Assigned:
Status: Closed Package: *General Issues
PHP Version: 5.5.3 OS: Ubuntu Linux
Private report: No CVE-ID: None
 [2013-09-18 17:51 UTC] flack at contentcontrol-berlin dot de
Description:
------------
See the script below. The expected output is

int(4)

instead, I get 

int(0)

I tested on the Ubuntu packages for php 5.3.10, 5.4.4 and 5.5.3.

When I use 

file_put_contents($src, $dst)

instead of copy(), it works as expected. Also, when I use fopen() and stream_copy_to_stream(). Only the plain copy() function doesn't behave as expected. Everything is on the same hard disk and was tested on three different machines (Ubuntu 12.04, 13.04 and Debian 7).


Test script:
---------------
$src = '/tmp/file.txt';
touch ($src);
file_put_contents($src, 'test');
$dst = tempnam('/tmp', 'dst');
copy($src, $dst);
var_dump(filesize($dst));

Expected result:
----------------
int(4)

Actual result:
--------------
int(0)

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-18 17:53 UTC] flack at contentcontrol-berlin dot de
Typo: Should read

file_put_contents($src, file_get_contents($dst))

for the version that works
 [2013-09-18 17:54 UTC] flack at contentcontrol-berlin dot de
Argh, third time's the charm:

file_put_contents($dst, file_get_contents($src))

is working
 [2013-10-10 02:52 UTC] haoustc at gmail dot com
that seems a problem.
 [2013-10-12 00:31 UTC] flack at contentcontrol-berlin dot de
I've noticed that as a workaround, you can call clearstatecache() before calling filesize(). So the problem isn't really that the file is not copied, but rather that the information statcache is stale.
 [2014-04-14 02:23 UTC] stas@php.net
-Summary: copy() doesn't work when destination filename is created by tempnam() +Summary: filesize() returns wrong result after copy
 [2014-04-20 22:28 UTC] stas@php.net
Automatic comment on behalf of buritomath@yahoo.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a18cec1b865994735e5b4ab757ccc1a14f8607ff
Log: Fix bug #65701: Do not use cache for file file copy
 [2014-04-20 22:28 UTC] stas@php.net
-Status: Open +Status: Closed
 [2014-04-25 23:25 UTC] ab@php.net
Automatic comment on behalf of buritomath@yahoo.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a18cec1b865994735e5b4ab757ccc1a14f8607ff
Log: Fix bug #65701: Do not use cache for file file copy
 [2014-04-25 23:29 UTC] ab@php.net
Automatic comment on behalf of buritomath@yahoo.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a18cec1b865994735e5b4ab757ccc1a14f8607ff
Log: Fix bug #65701: Do not use cache for file file copy
 [2014-05-01 14:59 UTC] tyrael@php.net
Automatic comment on behalf of buritomath@yahoo.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a18cec1b865994735e5b4ab757ccc1a14f8607ff
Log: Fix bug #65701: Do not use cache for file file copy
 [2014-10-07 23:15 UTC] stas@php.net
Automatic comment on behalf of buritomath@yahoo.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=a18cec1b865994735e5b4ab757ccc1a14f8607ff
Log: Fix bug #65701: Do not use cache for file file copy
 [2014-10-07 23:26 UTC] stas@php.net
Automatic comment on behalf of buritomath@yahoo.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=a18cec1b865994735e5b4ab757ccc1a14f8607ff
Log: Fix bug #65701: Do not use cache for file file copy
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC