Timewaster's Guide Archive

General => Rants and Stuff => Topic started by: The Holy Saint, Grand High Poobah, Master of Monkeys, Ehlers on July 29, 2008, 01:15:14 AM

Title: FORTRAN SMASH
Post by: The Holy Saint, Grand High Poobah, Master of Monkeys, Ehlers on July 29, 2008, 01:15:14 AM
ok, php, not fortran.

Code: [Select]
$docu_content='string information';
$newloc = '/home/clients/herbertlives.com/www/books/' . $orig;
if (file_put_contents('$newloc', '$docu_content')) {
print '<a href="' . $orig . '">File Created</a>';
} else {
print 'file creation failed';
}
($orig comes from POST data earlier)

now, my understanding is that if file_put_contents() is successful it returns the number of bytes written. Otherwise it returns false.
but all it does here is kill the script.
It does the same thing if I have a variable equal to the file_put_contents() statement and use that variable for the if statement. The script dies when it hits file_put_contents(), which i've tested by moving a print statement around. works fine before it's called, not immediately after.

anyway, jsut very very angry about this right now and no one who knows PHP is online right now to talk to me. so I had to spew it somewhere.
Title: Re: FORTRAN SMASH
Post by: Miyabi on July 29, 2008, 02:37:30 AM
Maybe this is just because I can't see like script you excluded here, but you would first have to call the file_put_contents() function earlier in the script, or define its parameters before you could check its paramaters.

It's like saying IF there's a basketball and soccer ball in the bag . . . but you didn't define WHAT was in the bag first,  and we couldn't look because that space hasn't been defined and could be anything or nothing, we wouldn't know what to do.

With what information you gave me this is all I could come up with.
Title: Re: FORTRAN SMASH
Post by: The Holy Saint, Grand High Poobah, Master of Monkeys, Ehlers on July 29, 2008, 03:46:46 AM
i've moved it around.

like, if I put

$somevar = file_put_contents('$newloc', '$docu_content');

and then check against $somevar

Or if I even just put

file_put_contents('$newloc', '$docu_content');

it kills the script.
I'd understand if it were returning false and just not writing the file. But it's like I'm putting DIE; there instead of file_put_contents().
v. irritating.
Title: Re: FORTRAN SMASH
Post by: Spriggan on July 30, 2008, 09:15:41 PM
easy fix.

if (file_put_contents('$newloc', '$docu_content'))  is your problem, since file_put_contents doesn't return true this statement will never happen, you need to change it to if (file_put_contents('$newloc', '$docu_content')!=false)  for this to work.