gm04030276 Posted July 24, 2006 Share Posted July 24, 2006 this is a script which i wrote to handle a request from a form in my self built admin portal. The form simply asks for the date via 3 drop down menus, day, month and year and a password and is then sent here in the hope of opening the log file for that date as the logs are written into files by what date it is using gmdate("Mdy"); for the filename. i cannot get this script to open the file though, it keeps saying:(note i have edited some of the file paths for obvious reasons, i have however checked them all to be right)[color=red]Warning: filesize(): Stat failed for Resource id #3 (errno=2 - No such file or directory) in /home/fhlinux210/c/closertohim.co.uk/user/htdocs/the path to script/logsapp.php on line 20[/color][color=blue]<?php$pass = md5($_REQUEST['pass'] ); [color=green]script asks for password to view files[/color]$passfil = fopen("../../../passhash.txt", "r");$passr = fread($passfil, 32);fclose($passfil);$day = $_REQUEST['day'] ;$month = $_REQUEST['month'] ;$year = $_REQUEST['year'] ; if($pass == $passr){ $date = "$month$day$year"; $location = "http://www.closertohim.co.uk/folder/folder/" .$date; echo $location; $datafil = fopen("http://closertohim.co.uk/folder/folder/" . $date, "r"); if(filesize($datafil) > 0){ $data = fread($datafil, filesize($datafil)); }else{ echo "error in log file size\n$!"; } include('logs.php'); }else{ echo "Incorrect password, please try <a href=\"logs.php\">again</a>"; } ?>[/color] Quote Link to comment https://forums.phpfreaks.com/topic/15522-baffled/ Share on other sites More sharing options...
craygo Posted July 24, 2006 Share Posted July 24, 2006 If the file is located on the same server as the script, you may be better off calling for the file using the absolute path rather than the url. do the files have an extention. ie: txt or log, because you are not showing any in the script.Also you don't have to come out of you quotes for the variable[code]$location = "http://www.closertohim.co.uk/folder/folder/$date";[/code]also this line[code]if(filesize($datafil) > 0){[/code]should be this[code]if(filesize($datafil > 0)){[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/15522-baffled/#findComment-63033 Share on other sites More sharing options...
gm04030276 Posted July 24, 2006 Author Share Posted July 24, 2006 there are no extensions on the files (should there be, i was wondering that)i will try the ABSOLUTE path, i was using the path from the directory i was in ie ../../../folder/file and that didnt work so i tried using the url. i will try with absolute path now and post back Quote Link to comment https://forums.phpfreaks.com/topic/15522-baffled/#findComment-63037 Share on other sites More sharing options...
Chips Posted July 24, 2006 Share Posted July 24, 2006 [quote author=craygo link=topic=101715.msg402763#msg402763 date=1153765151]also this line[code]if(filesize($datafil) > 0){[/code]should be this[code]if(filesize($datafil > 0)){[/code][/quote]I disagree there, you're asking if the filesize is greater than zero - you have it right - so dont' change it.I'd personally look here first:[code]if($pass == $passr){ $date = "$month$day$year";[/code]Should this not be:[code]$date = $month . $day . $year;[/code]It looks like string concatenation to me, at which point - you should concatenate them (my spelling is bad, i know).This [code]$location = "http://www.closertohim.co.uk/folder/folder/" .$date;[/code]looks fine to me again, concatenating the date to the end of that url and storing it in teh variable $location.Does it exist though? If you stick the date on, does that file exist?a file by the name of:http://www.closertohim.co.uk/folder/folder/05062006 or something - where is the extension to this file?I would look at these two places first, and then see how you get on from there. Quote Link to comment https://forums.phpfreaks.com/topic/15522-baffled/#findComment-63153 Share on other sites More sharing options...
gm04030276 Posted July 24, 2006 Author Share Posted July 24, 2006 putting the date into the variable by not concatenating them is ok, i got it just to print that to screen to see if that was were the prob was and it said the name right, as far as i can tell, the filename is getting changed from what is in the variable because i have got it to print out at several places to make sure it was alrightit says in the error messageWarning: filesize(): Stat failed for Resource id #3 (errno=2 - No such file or directory) in /home/fhlinux210/c/closertohim.co.uk/user/htdocs/path to file/logsapp.php on line 20so i asume that that means the name has been changed to resource id #3 (i dont really know much about reading error messages in php, i know what i need to know to do what i need to do!)it keeps saying the file doesnt exist but im sure the file name (capitalization aswell!) is correct at least going into the filesize function, it all seems to go wrong there and i havent changed it, because it doesnt make sense, i was right the first time in comparing one to the other.ill try the string concatenation for the date anyway and just keep tweeking, see what happens! Quote Link to comment https://forums.phpfreaks.com/topic/15522-baffled/#findComment-63158 Share on other sites More sharing options...
shoz Posted July 24, 2006 Share Posted July 24, 2006 [quote=gm04030276]$datafil = fopen("http://closertohim.co.uk/folder/folder/" . $date, "r");if(filesize($datafil) > 0){[/quote][url=http://www.php.net/filesize]filesize()[/url] takes a string argument. You're passing it the returned resource from [url=http://www.php.net/fopen]fopen[/url].Pass the same string given to fopen to filesize. Quote Link to comment https://forums.phpfreaks.com/topic/15522-baffled/#findComment-63162 Share on other sites More sharing options...
gm04030276 Posted July 24, 2006 Author Share Posted July 24, 2006 so i want to send it the file rather than the file handle! well that makes lots of sense!!!! gdgd! lets go try that! Quote Link to comment https://forums.phpfreaks.com/topic/15522-baffled/#findComment-63164 Share on other sites More sharing options...
gm04030276 Posted July 24, 2006 Author Share Posted July 24, 2006 thats what it was the whole flippin time! thank you soooo much! woohoo! Quote Link to comment https://forums.phpfreaks.com/topic/15522-baffled/#findComment-63172 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.