PHP Files
Okay, I'm using the following code
$getswf = @fopen($_GET["url"], "r");
if (! $getswf){
die("Error: Failed to open the file.\n");
}
//$filebuffer = @fread($getswf, filesize($_GET["url"]));
$filebuffer = fread($getswf, (180542));
fclose($getswf);
$a = fopen("test", "w");
fwrite($a, $filebuffer);
fclose($a);
}```
and When I check the file "test" it's only 9kb, rather than 177kb like the original.. why is this?
The file's size is deffintely 180542.
Also, filesize($_GET["url"]) failed, and I checked the allow_url_fopen was on.
Thanks for any help.
Might be nice to mention why fread() fails here. PHP.net says:
fread() reads up to length bytes from the file pointer referenced by handle . Reading stops as soon as one of the following conditions is met:
* length bytes have been read
* EOF (end of file) is reached
* a packet becomes available (for network streams)
* 8192 bytes have been read (after opening userspace stream)
Pay attention to the last one. However, you can make a loop which keeps reading 8192 bytes until EOF has been reached. Not that that is a smart thing to do. PHP.net states:
If you just want to get the contents of a file into a string, use file_get_contents() as it has much better performance than the code above.
GTADarkDude wrote: Might be nice to mention why fread() fails here. PHP.net says: [quote] fread() reads up to length bytes from the file pointer referenced by handle . Reading stops as soon as one of the following conditions is met:
* length bytes have been read
* EOF (end of file) is reached
* a packet becomes available (for network streams)
* 8192 bytes have been read (after opening userspace stream)
Pay attention to the last one. However, you can make a loop which keeps reading 8192 bytes until EOF has been reached. Not that that is a smart thing to do. PHP.net states:
If you just want to get the contents of a file into a string, use file_get_contents() as it has much better performance than the code above. [/quote] You, sir, just earned 20 CPs for going above and beyond to resolve a question. :D