Hi
everyone haven't posted for very long time.
I' m having problems with the file_get_contents function,
this function is present in 2 or 3 places in my application and opens a number of files.
Now it always worked until recently when I realized that for some files, not all of them, instead of returning the entire content of the file, it misses the first few line e.g. it start returning the content from the 7thor the 8th or any other line that is not the first one.
Anyone has any idea of what is happening?
Thanks
Silh

How are you determining whether it is missing the first few lines? Are you printing it out?

If the file contains certain escape characters, it can affect the print-out. For example, it may have CR instead of CRLF. Other escape sequences may trigger lines or characters not to show.

The first thing I would do to determine whether this is happening is to print out the length of the contents:

print strlen($contentsoffile);

and compare that to the size that the file system reports.

How are you determining whether it is missing the first few lines? Are you printing it out?

If the file contains certain escape characters, it can affect the print-out. For example, it may have CR instead of CRLF. Other escape sequences may trigger lines or characters not to show.

and compare that to the size that the file system reports.

What do you mean? I'm copying the conten of the file into another file, for some file it works and for others few lines at the beginning are missing.
how do I know that the first line are missing?
well if I design an application and I dont have idea of what to expect I should change job :D

is not a problem of escaping character because the content of the beginning of the file is the same for every file.
Now looking on internet I run into a post in which was mentioned a bug regarding the file_get_contents having problem with local file bigger than 512 Bytes... now that was the only post I could find in days of research where such a bug was mentioned...

anyone knows wheter this bug really exists? and why is not documented? how could I bypass the problem if not solve it?
Thank you
Silvano

Hi,
do you guys know if it is possible to monitor what the function file_get_contents does? like to see if it buffers the content somewhere or how it starts incrementing the pointer to the file's lines, maybe forsome reason an offset i set somewhere even though it should be zero since I didnt specified in the function call.
So maybe it would be possible to see at least why it jumps the first lines and from there maybe I could find a way to work around it?
Thanks again
Silh

@edwinhermann
do you think that storing the content of a file in an object, storing the object in a registry pattern and then re-copyng the content from the registry class to another file could actually change escape characters like CR into CRLF?
If so do you know how to avoid it?
Thanks for helping
I had people stating that the impossible is happening :)
Silh

Hi,
May be you can use addslashes function.

prem

how to open .doc file in php

how to open .doc file in php

Hi,
Try this code to open the .doc file.If it is not opened try to check the type of .doc file by using print_r($_FILES) and change the application/octet-msword and specify the type.

$filename="sample";
header("Content-type: application/octet-msword");
header("Content-Disposition: attachment; filename=".$filename.".doc");
header("Pragma: no-cache");
header("Expires: 0");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.