PHP Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>] - php

I've noticed that the directory on which one of the PHP script is installed have very large error_log file almost of 1GB size, mostly the errors are generated by coding on line 478 and 479.. example of the error from error_log file is below:
PHP Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for /home/khan/public_html/folder/ZBall.jar in /home/khan/public_html/folder/index.php on line 478
PHP Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for /home/khan/public_html/folder/ZBall.jar in /home/khan/public_html/folder/index.php on line 479
I have the following coding, line 477 to 484
foreach ($mp3s as $gftkey => $gftrow) {
$ftimes[$gftkey] = array(filemtime($thecurrentdir.$gftrow),$gftrow);
$ftimes2[$gftkey] = filemtime($thecurrentdir.$gftrow);
}
array_multisort($ftimes2,SORT_DESC,$ftimes);
foreach ($ftimes as $readd) {
$newmp3s[] = $readd[1];
}
Please help me on this.
Thanks.. :)

The stat failed error would indicate that the file /home/khan/public_html/games/ZBall.jar either doesn't exist, or can't be read due to a permission error. Make sure the file exists in the place PHP is looking, as that seems like the most like cause of the problem.
Since it comes from the array $mp3s, make sure that array contains names of files that exist and modify it if not.

ask for the file before doing something with it. checm my edit:
<?php
foreach ($mp3s as $gftkey => $gftrow) {
if (file_exists($thecurrentdir.$gftrow)) {
$ftimes[$gftkey] = array(filemtime($thecurrentdir.$gftrow),$gftrow);
$ftimes2[$gftkey] = filemtime($thecurrentdir.$gftrow);
}
}
array_multisort($ftimes2,SORT_DESC,$ftimes);
foreach ($ftimes as $readd) {
$newmp3s[] = $readd[1];
}

There is a function on PHP.net site which removes a bug on Windows about filemtime
function GetCorrectMTime($filePath) {
$time = filemtime($filePath);
$isDST = (date('I', $time) == 1);
$systemDST = (date('I') == 1);
$adjustment = 0;
if($isDST == false && $systemDST == true)
$adjustment = 3600;
else if($isDST == true && $systemDST == false)
$adjustment = -3600;
else
$adjustment = 0;
return ($time + $adjustment);
}
source: http://php.net/manual/tr/function.filemtime.php#100692

Related

Using rename() which works but giving warning at the same time

OK I'm confused. This code is showing me an error but at same time is doing what I actually needed.
$dir = new DirectoryIterator('./');
foreach ($dir as $filename) {
if (mimes_content_type($filename) == 'txt') {
rename($filename, './txt/'.$filename);
}
}
Warning: rename(txt,./txt/txt.txt): Invalid argument in ./www/session/test.php on line 78
Some advices what i did wrong ?

Stat failed for uploaded files

I'm trying to get the last modification time to display when the file(s) were uploaded, but I am getting this error: Warning: stat(): stat failed for image.jpeg in /var/www/html/module/Admin/File.php on line 116
Here is the code that handles it:
public function getModificationTime($dir)
{
if (!is_dir($dir)) {
return false;
}
$scandir = scandir($dir);
$holder = array();
foreach ($scandir as $key => $values) {
$holder = stat($values);
}
return $holder;
}
What am I doing wrong? Any help would be appreciated.
stat() cannot find the file. Use the full path ($values contains only the file name):
$holder = stat($dir.'/'.$values);
You need to concatenate the directory name. It's looking for the file in the current directory, not the directory you're scanning.
$holder = stat($dir . '/' . $values);

PHP's move_uploaded_file error: Permission denied on Mac

I'm new to PHP and I seem to have a problem uploading file to the web server. I've made myself a simple form and have a PHP file to control the uploading but every time I run the code, I get an error. Here is the code:
<?php
$name = $_FILES['upload']['name'];
$temp = $_FILES['upload']['tmp_name'];
$error = $_FILES['upload']['error'];
if ($error = 0) {
move_uploaded_file($temp, "images/" . $name);
echo 'Success';
} else {
die ('$error');
}
?>
and this is the error:
Warning: move_uploaded_file(images/macbook.jpg): failed to open stream: No such file or directory in /Library/WebServer/Documents/doc/ch07/upload_check.php on line 7
Warning: move_uploaded_file(): Unable to move '/private/var/tmp/phpuMC0td' to 'images/macbook.jpg' in /Library/WebServer/Documents/doc/ch07/upload_check.php on line 7
Thanks in advance!
error assign vs evaluate
if ($error = 0) should be if ($error == 0)
name is from basename. also declare the target before.
$target_path_file = 'images/' .basename($_FILES['upload']['name']);
move_uploaded_file($temp, $target_path_file);

Warning: pdo_dummy::rowCount()

So i tried changing all my MySQL queries in order to use PDO..
After changing, I have some few errors like this..when trying to add a new comment in file.php, annoying thing is the comment is added but this error comes as well..
Warning: pdo_dummy::rowCount() Your last query was unsuccessful and returned FALSE
instead of a fetchable result. See pdo_error() to find out why. - caused by /home/user
/public_html/file.php, line 118, when calling pdo_affected_rows(); in /home/user
/public_html/includes/pdo_mysql.php on line 1068
On line 118 in file.php
if (pdo_affected_rows() == 1)
show_error_msg(T_("COMPLETED"), T_("COMMENT_ADDED"), 0);
else
show_error_msg(T_("ERROR"), T_("UNABLE_TO_ADD_COMMENT"), 0);
On Line 1068 in pdo_mysql.php
function pdo_trigger_error($msg, $level=E_USER_NOTICE) {
// locate source of last pdo_*() invocation
foreach ((debug_backtrace()) as $src) {
// skip any functions in the current file
if (empty($src["file"])) {
$src["file"] = "{main}";
$src["line"] = "-";
}
if ($src["file"] != __FILE__) {
$dir = dirname($src["file"]);
$file = basename($src["file"]);
$msg .= " - caused by $dir/<b>$file</b>, line <b>$src[line]</b>, when calling <a>$src[function]()</a>;";
break;
}
}
// pass on to actual error handler chain
trigger_error($msg, (($level == 1<<14) && (PHP_VERSION < 5.3)) ? E_USER_NOTICE : $level);
}
I'm thinking this error occurs as a result of conflict but not sure...
trigger_error($msg, (($level == 1<<14) && (PHP_VERSION < 5.3)) ? E_USER_NOTICE : $level);
The complete pdo_mysql.php script is here Using PDO_MySQL
Thanks.....

Php scandir() problems

I was wondering, my Scandir() function works on a php $_GET variable, so the variable returns the folder, but I'm having a problem because I'm not sure how to echo out an error if there is a problem with with directory.
this is the error I am getting:
Warning: scandir(users/ro/f) [function.scandir]: failed to open dir: No such file or directory in C:\xampp\htdocs\OSO\desktop\main_content\file.php on line 31
This is my code
$folder = $_GET['file_folder'];
$directory = "users/$username/$folder";
if (scandir($directory, 0)) {
unset($documents[0], $documents[1]);
$documents = scandir($directory, 0);
// for each loop
} else {
echo "No such directory";
}
Cheers in advance
I would first check whether $directory exists using is_dir() before calling scandir():
if (is_dir($directory)) {
$filenames = scandir($directory, 0);
// do something
} else {
echo "No such directory";
}

Categories