473,706 Members | 2,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filesize inconsistant

Not sure whether this is something Im doing wrong or just something
the filesize() function doesnt support but...

<?
$fsize1 = filesize("foo.t xt");
$fp = fopen("foo.txt" ,a);
$time = time();
fputs($fp,$time );
fclose($fp);
$fsize2 = filesize("foo.t xt");
echo $fsize1." ".$fsize2;
?>

this code always reports the $fsize1 equal to $fsize2 when surely they
should be different?
Jul 17 '05 #1
5 1631
David <bi****@hotmail .com> wrote:
this code always reports the $fsize1 equal to $fsize2 when surely they
should be different?


This is a clear RTFM:
http://nl2.php.net/manual/en/function.filesize.php
"Note: The results of this function are cached."
Jul 17 '05 #2
David wrote:
$fp = fopen("foo.txt" ,a);
You mean "a", not a.
this code always reports the $fsize1 equal to $fsize2 when surely they
should be different?


http://php.net/clearstatcache is your friend.

Kristian

Jul 17 '05 #3
> This is a clear RTFM:

Yeh thanks. Just in case anyone cares you can achieve what I wanted
like this as well:

$fp = fopen($filename ,"r");
fseek($fp, 0, SEEK_END);
$filesize1 = ftell($fp);
fclose($fp);

$time = time();
$fp = fopen($filename ,"w");
fputs($fp, $time);
fclose($fp);

$fp = fopen($filename ,"r");
fseek($fp, 0, SEEK_END);
$filesize2 = ftell($fp);
fclose($fp);
Jul 17 '05 #4
David <bi****@hotmail .com> wrote:
Yeh thanks. Just in case anyone cares you can achieve what I wanted
like this as well:

$fp = fopen($filename ,"r"); fseek($fp, 0, SEEK_END); $filesize1 = ftell($fp);
fclose($fp); $time = time(); $fp = fopen($filename ,"w"); fputs($fp, $time); fclose($fp); $fp = fopen($filename ,"r"); fseek($fp, 0, SEEK_END); $filesize2 = ftell($fp);
fclose($fp);


But that will always return the same filesize ("w" truncates file)
(unless you happend to to sumble upon a switch from x to x+ digits (last
time that happend was in 2001 IIRC, and will not happen for some time
:))

Jul 17 '05 #5
It will work, but only the first time you run it. If you replace $time
with data of varying length (as is the case for me) it will always
give different sizes.
David <bi****@hotmail .com> wrote:
Yeh thanks. Just in case anyone cares you can achieve what I wanted
like this as well:

$fp = fopen($filename ,"r"); fseek($fp, 0, SEEK_END); $filesize1 = ftell($fp);
fclose($fp);
$time = time(); $fp = fopen($filename ,"w"); fputs($fp, $time); fclose($fp);
$fp = fopen($filename ,"r"); fseek($fp, 0, SEEK_END); $filesize2 = ftell($fp);
fclose($fp);


But that will always return the same filesize ("w" truncates file)
(unless you happend to to sumble upon a switch from x to x+ digits
(last
time that happend was in 2001 IIRC, and will not happen for some time
:))
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2264
by: Phil Powell | last post by:
// PROCESS XML CONTENT INTO DYNAMICALLY-NAMED ARRAYS foreach (array('mime', 'state', 'country') as $val) { $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, ${$val . 'XML'}, ${$val . 'XMLArray'}, $tags); xml_parser_free($parser); $myXMLArray = ${$val . 'XMLArray'}; for ($i = 1; $i < @sizeof($myXMLArray) - 1; $i++) { if ($myXMLArray) {
2
11695
by: IWP506 | last post by:
I just CANNOT figure out what is wrong with this! ------ $op1f = fopen("./test.txt","r"); $op1 = fread($op1f, filesize($op1f)); ------
1
1920
by: dharper | last post by:
I have a table that seems to have a bad index. When I do the following query I get inconsistant and needless to say incorrect results. select count(*) from mytable where mycolumn = 1 If I remove the index from "mycolumn" the query works correctly. If I add the index back (even with a new name etc...) it doesn't work right. Has anyone ran into this? or does anyone know how I can fix this
4
5464
by: Ken | last post by:
I would like to measure the fileSize of the image (without uploading it - php). I use: var size_pic = document.getElementById('num1').childNodes.fileSize; alert("size = " + size_pic); which works on IE with one exception. With a first time displayed image, the script displays a size= -1 The image is displayed on the first pass. The fileSize script is located after the
3
3388
by: Arjen | last post by:
Hello, When I have read a file with x.xxx.xxx.xxx bytes it is sometimes handy to show it in an diverent format than bytes. Is there a handy way to do this? Or is there a function for it? When it is a big file I want to see a MB size and when it is a lower file size then I want to see a kB size for example.
0
1496
by: Bob | last post by:
I have a sql command with a SearchDate parameter of type date. When I execute its stored procedure from Query Analyzer (to SS2K) with a date out of the valid datetime range, EXEC @SearchDate = '11/1/0200 12:00:00 AM' I get no error because the stored procedure properly handles out of range dates by ignoring them. If I send the sql command on its merry way properly paramaterized in .Net,
3
4371
by: mosscliffe | last post by:
I get a list of filenames from a directory with the following code, but I can not work out how to get the filesize of the filename I have just found. I guess it is fileinfo.length, but I can not see how to turn my filename(string) into a statement which would give me the filesize - the brain is very slow today. Any help gratefully appreciated. Dim files() As String = System.IO.Directory.GetFiles(root, patt)
1
2522
by: codejunkie | last post by:
Hi, I am running a suite of tests of a WIN 32 application. Every test launches the same application, checks if the Application has a Main Window handle and then proceeds. However i am noticing when i run a reasonably large ( 80-90) number of tests one after the other the Main Window handle API displays inconsistant behavior. About 70% of the time my application returns a valid Main WIndow handle
2
4662
by: Eric Layman | last post by:
I have checked this setting in my php.ini allow_url_fopen = On It is ON be default. According to the PHP documentation: it stated that as of php5, filesize supports the reading of remote html files:
0
8692
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9276
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9145
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7897
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectóplanning, coding, testing, and deploymentówithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4705
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2495
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2084
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.