Php warning stat failed

Php – filemtime “warning stat failed for”

I’m trying to create a function that deletes all the files with «xml» or «xsl» extension that has been created one day ago. But I’m getting this warning on each file I have:

Warning: filemtime() [function.filemtime]: stat failed for post_1003463425.xml in /home/u188867248/public_html/ampc/library.php on line 44

All the files of this directory have the same structure name «post_ + randomNum + .xml» (example: post_1003463425.xml or post_1456463425.xsl). So I think it’s not an encoded problem (like I saw in other questions).

The code of my function is this:

 function deleteOldFiles() < if ($handle = opendir('./xml')) < while (false !== ($file = readdir($handle))) < if(preg_match("/^.*\.(xml|xsl)$/i", $file))< $filelastmodified = filemtime($file); if ( (time()-$filelastmodified ) >24*3600) < unlink($file); >> > closedir($handle); > > 

Best Solution

I think the problem is the realpath of the file. For example your script is working on ‘./’, your file is inside the directory ‘./xml’. So better check if the file exists or not, before you get filemtime or unlink it:

 function deleteOldFiles() < if ($handle = opendir('./xml')) < while (false !== ($file = readdir($handle))) < if(preg_match("/^.*\.(xml|xsl)$/i", $file))< $fpath = 'xml/'.$file; if (file_exists($fpath)) < $filelastmodified = filemtime($fpath); if ( (time() - $filelastmodified ) >24*3600) < unlink($fpath); >> > > closedir($handle); > > 
Regex – Regular Expression for alphanumeric and underscores

To match a string that contains only those characters (or an empty string), try

Читайте также:  Spring Security Example

This works for .NET regular expressions, and probably a lot of other languages as well.

^ : start of string [ : beginning of character group a-z : any lowercase letter A-Z : any uppercase letter 0-9 : any digit _ : underscore ] : end of character group * : zero or more of the given characters $ : end of string 

If you don’t want to allow empty strings, use + instead of *.

As others have pointed out, some regex languages have a shorthand form for [a-zA-Z0-9_] . In the .NET regex language, you can turn on ECMAScript behavior and use \w as a shorthand (yielding ^\w*$ or ^\w+$ ). Note that in other languages, and by default in .NET, \w is somewhat broader, and will match other sorts of Unicode characters as well (thanks to Jan for pointing this out). So if you’re really intending to match only those characters, using the explicit (longer) form is probably best.

Php – filemtime() [function.filemtime]: stat failed for filenames with umlauts

With the following code snippet I found out that the file encoding on Windows 7 is «ISO-8859-1»:

$scandir = scandir('.') $encoding = mb_detect_encoding($scandir[0], 'ISO-8859-1, UTF-8, ASCII'); echo $encoding; 

I’ve read that utf8_decode converts a UTF-8 string to ISO-8859-1 so I ended up with this small code that works for my project:

$file = 'C:/pictures/München.JPG'; $lastModified = @filemtime($file); if($lastModified == NULL) $lastModified = filemtime(utf8_decode($file)); echo $lastModified; 

Thank you to all who have submitted a comment. You have steered me in the right direction. 🙂

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning PHP filesize(): stat failed #4452

Warning PHP filesize(): stat failed #4452

Comments

Lately i´ve been getting ALOT of these error messages:

Warning PHP filesize(): stat failed for /var/www/owncloud/data/enoch/files/DirektUppladdning/20130602_210025_2.jpg at /var/www/owncloud/lib/files/storage/local.php#74 2013-08-15T14:56:01+00:00
Warning PHP filesize(): stat failed for /var/www/owncloud/data/enoch/files/DirektUppladdning/20130602_210025_1.jpg at /var/www/owncloud/lib/files/storage/local.php#74 2013-08-15T14:55:39+00:00
Warning PHP filesize(): stat failed for /var/www/owncloud/data/enoch/files/DirektUppladdning/20130602_205736_Richtone(HDR).jpg at /var/www/owncloud/lib/files/storage/local.php#74 2013-08-15T14:55:16+00:00

I don´t know if it´s a bug, or if it has something to do with my coniguration?

I use OC 5.0.10 and Ubuntu Server 12.04 LTS. Also for mounting webdav I use a program called «Netdrive» for Windows.

If you want any logs or something else I´m happy to provide them.

The text was updated successfully, but these errors were encountered:

Источник

PHP WHY Warning: filemtime(): stat failed for

Warning: filemtime(): stat failed for includes\img\defaultimg.jpg in 

I read and researched but found nothing useful

in the php manual only says this:

If PHP's integer type is only 32 bits on your system, filemtime() will fail on files over 2GB with the warning "stat failed". All stat()-related commands will exhibit the same behavior. 

this is my code works fine in xammp, but not in production

 $dirimg="includes/img/"; //this one also throws warning $filename = "".$dirimg."".$resultsb['Img'].".jpg"; //the path if(file_exists ($filename))< // exists? $timeimg=filemtime($filename); $srci="".$dirimg."".$resultsb['Img'].".jpg?=".$timeimg.""; >else <$timeimg=filemtime("includes\img\defaultimg.jpg"); //another path, the file does exists $srci="includes\img\defaultimg.jpg?=".$timeimg.""; >// 

both throw the same warning in the respective path, the file exits btw

the image can be seen, but i need to know when it is modified so the browser refreshes it

Answer

Solution:

It was the slashes hahaha , the server is in Linux So, they have to be like this «includes/img/defaultimg.jpg?=» instead of «includes\img\defaultimg.jpg? center»> Write your answer

Share solution ↓

Additional Information:

Didn’t find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Similar questions

Find the answer in similar questions on our website.

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

About the technologies asked in this question

PHP

PHP (from the English Hypertext Preprocessor — hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/

Welcome to programmierfrage.com

programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.

Get answers to specific questions

Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.

Help Others Solve Their Issues

Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.

Источник

Php – Warning: filemtime(): stat failed for

I am getting an error when I am trying to upload files to my webserver. They are being uploaded fine, it is when I am pulling details from the file, it throws an error. Also when clicking the uploaded file it puts the wrong path it brings up ‘./filename.jpg’ not ‘uploads/filename.jpg’ The upload folder is /uploads/

I believe it is dealing with the real path of the file but I am unsure of how to fix it.

Here is the code sample I am using.

Best Solution

Try using this. The path was not pulling through for the dirArray. Need to append $path to the arraypath

Html – What are valid values for the id attribute in HTML

For HTML 4, the answer is technically:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits (9), hyphens («-«), underscores («_»), colons («:»), and periods («.»).

HTML 5 is even more permissive, saying only that an id must contain at least one character and may not contain any space characters.

The id attribute is case sensitive in XHTML.

As a purely practical matter, you may want to avoid certain characters. Periods, colons and ‘#’ have special meaning in CSS selectors, so you will have to escape those characters using a backslash in CSS or a double backslash in a selector string passed to jQuery. Think about how often you will have to escape a character in your stylesheets or code before you go crazy with periods and colons in ids.

For example, the HTML declaration is valid. You can select that element in CSS as #first\.name and in jQuery like so: $(‘#first\\.name’). But if you forget the backslash, $(‘#first.name’) , you will have a perfectly valid selector looking for an element with id first and also having class name . This is a bug that is easy to overlook. You might be happier in the long run choosing the id first-name (a hyphen rather than a period), instead.

You can simplify your development tasks by strictly sticking to a naming convention. For example, if you limit yourself entirely to lower-case characters and always separate words with either hyphens or underscores (but not both, pick one and never use the other), then you have an easy-to-remember pattern. You will never wonder «was it firstName or FirstName ?» because you will always know that you should type first_name . Prefer camel case? Then limit yourself to that, no hyphens or underscores, and always, consistently use either upper-case or lower-case for the first character, don’t mix them.

A now very obscure problem was that at least one browser, Netscape 6, incorrectly treated id attribute values as case-sensitive. That meant that if you had typed id=»firstName» in your HTML (lower-case ‘f’) and #FirstName < color: red >in your CSS (upper-case ‘F’), that buggy browser would have failed to set the element’s color to red. At the time of this edit, April 2015, I hope you aren’t being asked to support Netscape 6. Consider this a historical footnote.

Javascript – Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”

Three reasons. Encouraging the use of # amongst a team of developers inevitably leads to some using the return value of the function called like this:

But then they forget to use return doSomething() in the onclick and just use doSomething() .

A second reason for avoiding # is that the final return false; will not execute if the called function throws an error. Hence the developers have to also remember to handle any error appropriately in the called function.

A third reason is that there are cases where the onclick event property is assigned dynamically. I prefer to be able to call a function or assign it dynamically without having to code the function specifically for one method of attachment or another. Hence my onclick (or on anything) in HTML markup look like this:

onclick="someFunc.apply(this, arguments)" 

Using javascript:void(0) avoids all of the above headaches, and I haven’t found any examples of a downside.

So if you’re a lone developer then you can clearly make your own choice, but if you work as a team you have to either state:

Use href=»#» , make sure onclick always contains return false; at the end, that any called function does not throw an error and if you attach a function dynamically to the onclick property make sure that as well as not throwing an error it returns false .

The second is clearly much easier to communicate.

Источник

Оцените статью