elite_prodigy Posted January 17, 2009 Share Posted January 17, 2009 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 Link to comment https://forums.phpfreaks.com/topic/141202-i-fail-at-file-handling-apparently-can-someone-help/ Share on other sites More sharing options...
dawsba Posted January 17, 2009 Share Posted January 17, 2009 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 Link to comment https://forums.phpfreaks.com/topic/141202-i-fail-at-file-handling-apparently-can-someone-help/#findComment-739050 Share on other sites More sharing options...
Mark Baker Posted January 17, 2009 Share Posted January 17, 2009 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 Link to comment https://forums.phpfreaks.com/topic/141202-i-fail-at-file-handling-apparently-can-someone-help/#findComment-739051 Share on other sites More sharing options...
elite_prodigy Posted January 17, 2009 Author Share Posted January 17, 2009 Changing it to 1024 does work, but I don't get the whole file. Link to comment https://forums.phpfreaks.com/topic/141202-i-fail-at-file-handling-apparently-can-someone-help/#findComment-739053 Share on other sites More sharing options...
Mark Baker Posted January 17, 2009 Share Posted January 17, 2009 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); Link to comment https://forums.phpfreaks.com/topic/141202-i-fail-at-file-handling-apparently-can-someone-help/#findComment-739055 Share on other sites More sharing options...
kenrbnsn Posted January 17, 2009 Share Posted January 17, 2009 Is this file on the same server as your script? If so, why are you using a URL to open it, when you should be using a local file name? Ken Link to comment https://forums.phpfreaks.com/topic/141202-i-fail-at-file-handling-apparently-can-someone-help/#findComment-739063 Share on other sites More sharing options...
elite_prodigy Posted January 17, 2009 Author Share Posted January 17, 2009 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. Link to comment https://forums.phpfreaks.com/topic/141202-i-fail-at-file-handling-apparently-can-someone-help/#findComment-739070 Share on other sites More sharing options...
kenrbnsn Posted January 17, 2009 Share Posted January 17, 2009 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. We have to see your code for this to tell you why. Ken Link to comment https://forums.phpfreaks.com/topic/141202-i-fail-at-file-handling-apparently-can-someone-help/#findComment-739091 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.