Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filesize() return 0 ?

Tags:

php

filesize

im trying to insert an array values into the file using foreach.. and if the file size became up to 1MB (1000000byte). the script create a new file and put the value inside...

this is the code what i used :

foreach($array as $code){  

if(filesize($file_name) < '1000000'){
    $update_file = file_get_contents($file_name);
    file_put_contents($file_name,$update_file.$code);
}else{
    $open = fopen($file_name.rand('99999'),'w');
    file_put_contents($file_name,$code);

    }
echo filesize($file_name);
}

now the problem is the function "filesize()" is always returning 0,, but if i remove the code above it and put echo filesize($file_name); only in the page .. it return the right value (size of file), the script also make only 1 file even it became more than 1MB because the filesize is 0 as filesize() function return !.

i checked this question PHP Problem : filesize() return 0 with file containing few data? but it still not working even i follow the answer #1

i wish that you understand my problem.. and im sorry for my english.

like image 976
Programmer4me Avatar asked Sep 10 '11 06:09

Programmer4me


People also ask

How to check the filesize in PHP?

To get the file size, we will use filesize() function. The filesize() function returns the size of a file in bytes. This function accepts the filename as a parameter and returns the size of a file in bytes on success and False on failure.

How can I get PDF size in PHP?

The filesize() function returns the size of a file.

How to check image file size in PHP?

The getimagesize() function will determine the size of any supported given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondent HTTP content type.

How do you find the file size?

Right-click the file and click Properties. The image below shows that you can determine the size of the file or files you have highlighted from in the file properties window. In this example, the chrome. jpg file is 18.5 KB (19,032 bytes), and that the size on disk is 20.0 KB (20,480 bytes).


1 Answers

function filesize is cached internally
you need to explicitly use clearstatcache after each write

beside this, the usage of file_put_contents does not seem to be correct

please refer to the manual for more information

like image 91
ajreal Avatar answered Oct 18 '22 09:10

ajreal