Jump to content

Recommended Posts

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>";

 

Link to comment
https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604093
Share on other sites

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 

Link to comment
https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604094
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604096
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604097
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604101
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604102
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/315748-php-script-help/#findComment-1604105
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.