Jump to content

I fail at file handling, apparently, can someone help?


elite_prodigy

Recommended Posts

Well, once again, PHP decided it was going to hate me with it's very soul. (Can a code engine have a soul? Anyway...)

 

I'm trying to let people edit my CSS file, well, not everybody, but staff members through the control pannel I've provided for them.

 

When I try, PHP smiles and slaps me with this error:

 

 

Warning: filesize() [function.filesize]: stat failed for Resource id #11 in /home/exembar/public_html/team/php/editCSS.php on line 11

 

Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/exembar/public_html/team/php/editCSS.php on line 11

 

Here is the code:

 

<?php

if(!$user->permission('pages')){

error("100", "Access Denied", "You are unable to access this page because you do not have the proper permissions.");

}

$link		= fopen("http://exembarstudios.exofire.net/overall.css", 'r');

$css		= fread($link, filesize($link));

$page->setContent('

				<form name="modCSS" method="post" action="php/doEditCSS.php">

				<textarea class="file" name="css">'.$css.'</textarea>

				</form>

				');

?>

 

 

I mode on the css file set to 0644, but have tried changing them to 0664 which had not effect.

 

As always, you people are amazing, and all of your help is greatly appreciated.

 

-David

if you change filesize($link) to 1024 does it work

 

you could try

function getSizeFile($url) {
    if (substr($url,0,4)=='http') {
        $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
        if ( strcasecmp($x[0], 'HTTP/1.1 200 OK') != 0 ) { $x = $x['content-length'][1]; }
        else { $x = $x['content-length']; }
    }
    else { $x = @filesize($url); }

    return $x;
}

<- taken from php.net

filesize() wants a filename, not the filehandle

$filename = "http://exembarstudios.exofire.net/overall.css";
$link = fopen($filename, 'r');
$css = fread($link, filesize($filename));

However, I'm not sure how well filesize will work when the filename is a URL - it may use two calls: one to get the size of the data, the second to get the data for the fread() - rather than a local filesystem file

Changing it to 1024 does work, but I don't get the whole file.

$link = fopen("http://exembarstudios.exofire.net/overall.css", "r");
$css = '';
while (!feof($link)) {
  $css .= fread($link, 1024);
}
fclose($link);

Well, because in the past on this server, for some unknown reason, when I tried to access the local file through it's local filename and directory hierarchy it would attempt to get the file from the directory I was in, and then go down in the subdirectories.

 

I've fixed the errors, and this works now.

 

However, could anyone tell me why when I use fwrite() to write to a file opened with mode 'w' all of my quotes are escaped.

 

This is really messing up the CSS.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.