Ayush123 Posted January 1, 2023 Share Posted January 1, 2023 PHP script that provides a basic web-page asking for a date. That date is then used to get the log file for that date from a directory containing many log files (one for each date). If the log file exists, then it is downloaded; otherwise, the script returns with "No logs for that date". Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/ Share on other sites More sharing options...
Barand Posted January 1, 2023 Share Posted January 1, 2023 What have you tried so far? Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604085 Share on other sites More sharing options...
Ayush123 Posted January 1, 2023 Author Share Posted January 1, 2023 2 minutes ago, Barand said: What have you tried so far? i am stuck at the point where i need to compare the date to the log file Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604086 Share on other sites More sharing options...
Barand Posted January 1, 2023 Share Posted January 1, 2023 We aren't psychic. Code? Sample log file names? Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604087 Share on other sites More sharing options...
Ayush123 Posted January 1, 2023 Author Share Posted January 1, 2023 nothing specific. just an example. log files are just dates. if the date exists it downloads or prints. Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604088 Share on other sites More sharing options...
Ayush123 Posted January 1, 2023 Author Share Posted January 1, 2023 log file names are dates Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604089 Share on other sites More sharing options...
ginerjm Posted January 1, 2023 Share Posted January 1, 2023 A sample filename would be helpful to us to help give you right code. And perhaps the script that you have already written if you are having problems with would be nice. As Barand said - we are not psychic Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604090 Share on other sites More sharing options...
Ayush123 Posted January 1, 2023 Author Share Posted January 1, 2023 sorry, just starting on php. the files can be just text files. like 07-14-2022.txt. so the user will input a date. then i just need to check if that date exists in the directory then prints or download that file. Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604091 Share on other sites More sharing options...
Ayush123 Posted January 1, 2023 Author Share Posted January 1, 2023 or just any file created on the user inputted date. Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604092 Share on other sites More sharing options...
ginerjm Posted January 1, 2023 Share Posted January 1, 2023 So if you want to take a user's input of a valid date value and convert it to a text string to build the filename do this: $input_val = '12/01/22'; // sample value if ($dv = strtotime($input_val)) { $filename = date('m-d-y', $dv) . '.txt'; echo "For input of $input_val filename will be $filename<br>"; } else echo "Invalid date input: $input_val<br>"; Then you use the value created above ($filename) and do a search of your log folder like this: if (is_file($log_folder.$filename)) echo "Filename is in log<br>"; else echo "Filename $log_folder$filename not found in log<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604093 Share on other sites More sharing options...
Ayush123 Posted January 1, 2023 Author Share Posted January 1, 2023 3 minutes ago, ginerjm said: So if you want to take a user's input of a valid date value and convert it to a text string to build the filename do this: $input_val = '12/01/22'; // sample value if ($dv = strtotime($input_val)) { $filename = date('m-d-y', $dv) . '.txt'; echo "For input of $input_val filename will be $filename<br>"; } else echo "Invalid date input: $input_val<br>"; Then you use the value created above ($filename) and do a search of your log folder like this: if (is_file($log_folder.$filename)) echo "Filename is in log<br>"; else echo "Filename $log_folder$filename not found in log<br>"; thanks, hope i dont confuse you. so, lets say i ahve a directory with files. i just need to get the files for the user specified date, maybe using filemtime(). then if it exists download it Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604094 Share on other sites More sharing options...
ginerjm Posted January 1, 2023 Share Posted January 1, 2023 You said you wanted to use the date to identify the file by name. Now you are mentioning filemtime. Why? That is not what you first said. Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604095 Share on other sites More sharing options...
Ayush123 Posted January 1, 2023 Author Share Posted January 1, 2023 sorry i am new to this, not as 5 minutes ago, ginerjm said: You said you wanted to use the date to identify the file by name. Now you are mentioning filemtime. Why? That is not what you first said. sorry i am new to this, not as smart as you thats why i am asking for help. the best i can say is, i need to download files with the date provided by the user from a directory. i dont know how to simplify what i am asking Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604096 Share on other sites More sharing options...
ginerjm Posted January 1, 2023 Share Posted January 1, 2023 You showed us a sample filename that used a date value as part of its name. Isn't that how you want to identify files that your user wants to download? The filemtime function reads the date saved as part of the directory entry that represents the date/time of the last file change which isn't always visible. Step back and think about what you want to do. If it is the former I think I have given you the code to do that mostly. At least the identification part. Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604097 Share on other sites More sharing options...
Ayush123 Posted January 1, 2023 Author Share Posted January 1, 2023 i guess i need to make an array for the date of the files in the directory then compare it to the user specified date using filemtime() or filectime() Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604098 Share on other sites More sharing options...
Ayush123 Posted January 1, 2023 Author Share Posted January 1, 2023 yes, i need to access the files using file created time or modified time Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604099 Share on other sites More sharing options...
ginerjm Posted January 1, 2023 Share Posted January 1, 2023 So why did you not tell us that and why show us a sample file with a date as part of the name? Do you want to begin this discussion again? Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604100 Share on other sites More sharing options...
Ayush123 Posted January 1, 2023 Author Share Posted January 1, 2023 5 minutes ago, ginerjm said: You showed us a sample filename that used a date value as part of its name. Isn't that how you want to identify files that your user wants to download? The filemtime function reads the date saved as part of the directory entry that represents the date/time of the last file change which isn't always visible. Step back and think about what you want to do. If it is the former I think I have given you the code to do that mostly. At least the identification part. thanks for the help. sorry for the confussion Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604101 Share on other sites More sharing options...
ginerjm Posted January 1, 2023 Share Posted January 1, 2023 While you are re-thinking this.... There are 3 functions related to the file date - filemtime, fileatime & filectime. Which one is the most important to your project? And how will you be sure that you are downloading the correct file since you could have many files having the same date/time value? Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604102 Share on other sites More sharing options...
Ayush123 Posted January 1, 2023 Author Share Posted January 1, 2023 5 minutes ago, ginerjm said: While you are re-thinking this.... There are 3 functions related to the file date - filemtime, fileatime & filectime. Which one is the most important to your project? And how will you be sure that you are downloading the correct file since you could have many files having the same date/time value? thanks for still sticking around. filectime is the one i need to use. if there are multiple files with the same date, i will need to download all the file. Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604105 Share on other sites More sharing options...
ginerjm Posted January 1, 2023 Share Posted January 1, 2023 So - just because 2 or more files have the same internal date you want to download them both even if they have absolutely nothing to do with each other? Seems like an odd thing to write. Quote Link to comment https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604106 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.