Jump to content


Photo

baffled!


  • Please log in to reply
7 replies to this topic

#1 gm04030276

gm04030276
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 24 July 2006 - 05:59 PM

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)

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

<?php


$pass = md5($_REQUEST['pass'] );                script asks for password to view files
$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.closertoh...folder/folder/" .$date;
echo $location;
$datafil = fopen("http://closertohim.c...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>";
}

?>


#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 24 July 2006 - 06:19 PM

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

$location = "http://www.closertohim.co.uk/folder/folder/$date";

also this line
if(filesize($datafil) > 0){

should be this
if(filesize($datafil > 0)){

Ray




#3 gm04030276

gm04030276
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 24 July 2006 - 06:23 PM

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

#4 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 24 July 2006 - 10:11 PM

also this line

if(filesize($datafil) > 0){

should be this
if(filesize($datafil > 0)){

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:
if($pass == $passr){

      $date = "$month$day$year";
Should this not be:
$date = $month . $day . $year;
It looks like string concatenation to me, at which point - you should concatenate them (my spelling is bad, i know).
This
$location = "http://www.closertohim.co.uk/folder/folder/" .$date;
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.closertoh...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.

#5 gm04030276

gm04030276
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 24 July 2006 - 10:32 PM

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 alright

it says in the error message

Warning: 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 20

so 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!

#6 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 24 July 2006 - 10:38 PM


$datafil = fopen("http://closertohim.c...folder/folder/" . $date, "r");
if(filesize($datafil) > 0){

filesize() takes a string argument. You're passing it the returned resource from fopen.

Pass the same string given to fopen to filesize.

#7 gm04030276

gm04030276
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 24 July 2006 - 10:42 PM

so i want to send it the file rather than the file handle! well that makes lots of sense!!!! gdgd! lets go try that!


#8 gm04030276

gm04030276
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 24 July 2006 - 11:08 PM

thats what it was the whole flippin time! thank you soooo much! woohoo!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users