Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

PHP Files


ghost's Avatar
0 0

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.

ghost's Avatar
0 0

The original file is 177kb with a lot in it.

The new file (duplicate that the program makes) is 9kb.


ghost's Avatar
0 0

lol Yes because the content isn't there.

It basically only takes the first 9kb, or so it seems.


ghost's Avatar
0 0

Nope. It's making a duplicate, or at least it's supposed to be.


ghost's Avatar
0 0

Have you tried using file_get_contents() instead of fread()?


ghost's Avatar
0 0

Worked :)

Thanks mastergamer


GTADarkDude's Avatar
Member
0 0

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.


ghost's Avatar
0 0

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