Jump to content

Recommended Posts

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]
Link to comment
https://forums.phpfreaks.com/topic/15522-baffled/
Share on other sites

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


Link to comment
https://forums.phpfreaks.com/topic/15522-baffled/#findComment-63033
Share on other sites

[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.
Link to comment
https://forums.phpfreaks.com/topic/15522-baffled/#findComment-63153
Share on other sites

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!
Link to comment
https://forums.phpfreaks.com/topic/15522-baffled/#findComment-63158
Share on other sites


[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.
Link to comment
https://forums.phpfreaks.com/topic/15522-baffled/#findComment-63162
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.