Php get file version

stat

Gathers the statistics of the file named by filename . If filename is a symbolic link, statistics are from the file itself, not the symlink. Prior to PHP 7.4.0, on Windows NTS builds the size , atime , mtime and ctime statistics have been from the symlink, in this case.

lstat() is identical to stat() except it would instead be based off the symlinks status.

Parameters

Return Values

stat() and fstat() result format

Numeric Associative Description
0 dev device number ***
1 ino inode number ****
2 mode inode protection mode *****
3 nlink number of links
4 uid userid of owner *
5 gid groupid of owner *
6 rdev device type, if inode device
7 size size in bytes
8 atime time of last access (Unix timestamp)
9 mtime time of last modification (Unix timestamp)
10 ctime time of last inode change (Unix timestamp)
11 blksize blocksize of filesystem IO **
12 blocks number of 512-byte blocks allocated **

* On Windows this will always be 0 .

** Only valid on systems supporting the st_blksize type — other systems (e.g. Windows) return -1 .

*** On Windows, as of PHP 7.4.0, this is the serial number of the volume that contains the file, which is a 64-bit unsigned integer, so may overflow. Previously, it was the numeric representation of the drive letter (e.g. 2 for C: ) for stat() , and 0 for lstat() .

**** On Windows, as of PHP 7.4.0, this is the identifier associated with the file, which is a 64-bit unsigned integer, so may overflow. Previously, it was always 0 .

***** On Windows, the writable permission bit is set according to the read-only file attribute, and the same value is reported for all users, group and owner. The ACL is not taken into account, contrary to is_writable() .

The value of mode contains information read by several functions. When written in octal, starting from the right, the first three digits are returned by chmod() . The next digit is ignored by PHP. The next two digits indicate the file type:

mode file types
mode in octal Meaning
0140000 socket
0120000 link
0100000 regular file
0060000 block device
0040000 directory
0020000 character device
0010000 fifo

So for example a regular file could be 0100644 and a directory could be 0040755 .

In case of error, stat() returns false .

Note: Because PHP’s integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB.

Errors/Exceptions

Upon failure, an E_WARNING is emitted.

Changelog

Version Description
7.4.0 On Windows, the device number is now the serial number of the volume that contains the file, and the inode number is the identifier associated with the file.
7.4.0 The size , atime , mtime and ctime statistics of symlinks are always those of the target. This was previously not the case for NTS builds on Windows.

Источник

Get a file’s version in PHP

Since you are mentioning EXE files, I assume that you need this for a
Windows environment.

Читайте также:  Типы данных python задачи

Here, you can use the COM extension (http://www.php.net/com) as follows:

//create FSO instance
$fso = new COM(«Scripting.FileSystemObject»)
or die(«Could not create Scripting.FileSystemObject»);

$version = $fso->GetFileVersion(realpath(‘some.exe’));
print $version;

Another option, without using COM, would be to open the binary file and
search for the pattern F\0i\0l\0e\0V\0e\0r\0s\0i\0o\0n\0\0\0\0\0
The version is right behind that string:

$strFile = «c:\\my.exe»;
$fpFile = fopen($strFile, «rb»);
$strFileContent = fread($fpFile, filesize($strFile));
fclose($fpFile);

$strTagBefore = ‘F\0i\0l\0e\0V\0e\0r\0s\0i\0o\0n\0\0\0\0\0’;
$strTagAfter = ‘\0\0’;
if (preg_match(«/$strTagBefore(.*?)$strTagAfter/», $strFileContent,
$arrMatches))
print_r($arrMatches);
>

——BEGIN PGP SIGNED MESSAGE——
Hash: SHA1

I want to get the file version of a file in PHP.

Do somebody have the code for this?

Yeah, it’s called «Use a CVS or SVN repository for version tracking» and
«use external execution commands like shell_exec to query the repository».

Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
——BEGIN PGP SIGNATURE——
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDZK/f3jcQ2mg3Pc8RAmxYAJ4ztjXc/COKd51PaQT5h5SkGPtcSwCeM8rc
7GXQnAGTdtLs9noPiG2R4UU=
=9zCr
——END PGP SIGNATURE——

Do somebody have the code for this?

What do you mean? If you mean the file creation date/last modified date, you
can use the filectime/filemtime functions.

filectime does not return a «file creation date». Many operating
systems do not even maintain a file creation date. On the UNIX
variants that do keep a file creation date (only on UFS2 filesystems),
that isn’t what filectime returns.

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

Hi I’v been stuck on this problem for ages now. I have found that I’m not the only one with this problem, by looking through the different newsgroups. Hope you can help me! I know there is a.

In VS.2005 using VB.NET There are two versions on every project, The Assembly Version and the File Version. Why are there two different versions? As far as I can tell, there is not need for.

I am working in ASP.NET with C#. I have a text file which contains datas with delimiters. For example:- MSH|^~\$|DISCHARGE|CLAY COUNTY MEMORIAL|||200502110939| I also have an XML file created.

I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement — Every mdb table needs a PrimaryKey ( or maybe an index — i.

IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. .

Hi, I am writing to a file some basic information using the logging module. It is working but in the log file some line are printed several time. I had put some print debugging messages in the.

Hello everyone, here is what I want to do. I have a ATI video card and it allows me to setup profiles for monitor configurations and so forth. The shortcut to activate one of these profiles looks.

Hello, I have this non-standard XML file that I have to manually sort thru each day and verify whether various jobs finish successfully or not. This file isn’t a real XML file, so I cannot appear.

Hi all, I have a C++/CLI project (VS 2005) that produces a DLL that exports C bindings. Internally, this DLL contains routines compiled with /clr. I notice that my DLL doesn’t have a version.

Читайте также:  Javascript local file directory

Hello Gurus, i implemented the OpenFileDialog in my Windows Form Applications and it worked perfectly fine.However when it was run on a remote desktop i got the below error . .

The next Access Europe meeting will be on Wednesday 5 July 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central.

Hello, I want to share a page https://opensource-heroes.com/ with a rating of open-source developers sorted by sum of stars of their projects. There are also numerous current projects featured on.

Dijkstra�s algorithm is a method for solving the single-source shortest path problem on a graph, and can be applied in various fields such as computer networks and transportation. In the context of.

I�ve recently found a very interesting collection of terrible tips for C++ developers. Yes, that’s right, they are terrible! And the coolest thing is that the book is both useful and entertaining. .

Hey Guys, Using VB6: I have a 200 millisecond timer obj on a form with an RTF Obj on the form which contains RTF documentation. The timer commands Clipboard.Clear when the RichText Object.

Step right up, brave innovators and fearless pioneers of the coding world! As you’re about to learn, JavaScript can now do so much more! The gates of web3 and beyond await. We’re excited to share a.

My transaction table has tran code SSN, and an amount, followed by another Tran code for same SSN, and the Amount is -ve. I habe to create report that has SSN and amount (= psitive — negative) how ?

1. Define a Clear Vision and Strategy Before embarking on a digital transformation journey, it’s crucial to have a clear vision of what you want to achieve and develop a comprehensive strategy.

By using Bytes.com and it’s services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.

Источник

Several Approaches to Versioning Files in PHP

In a project at work I am in the process of putting some finishing touches on the frontend, and ran into a bit of a dilemna last week: how to use versioned static files with PHP with a minimum of work?

If you haven’t used versioned static files before, it’s a rather useful trick. You can configure Apache/Lighttpd/Nginx to inform browsers that a given file (or contents of a directory, or files with certain extensions, etc) won’t change in the next 5 minutes, 3 days, or even 10 years. This serves as a strong suggestion to the browser to cache the specified file and not attempt to reload it until the specified time. This lowers your bandwidth (serve fewer files), reduces server load (fewer http requests per pageview), and makes page load faster (another effect of having fewer http requests per pageview).

An awkward side-effect is that users won’t reload those files after you make changes unless they force-refresh or clear their browser cache (neither of which happen with great regularity). The standard solution to this is to add a version to the filename, i.e. styles.css becomes styles-1.css , and later styles-231.css . Returning to the problem, how should we add that version number to our files without needing to manually update our code with the newest file versions?

Читайте также:  Си шарп чем хорош

I see two general solutions to this problem, regardless of which we go with the usage is going to look the same,

"but the underlying mechanism will be a bit different.

Compile Time Version Discovery

Although much of the web is built on interpreted languages (PHP, CSS, JS, HTML), many projects nonetheless end up requiring a compile stage. For static files like CSS and JS that is typically sending the files through a compressor of some kind (the examples on this page will send the files through YUI Compressor).

Compilation gives a nice leverage point for assigning all the files the same version number, and then passing that context along to the server.

.css $BUILD/css» js $BUILD/js» java -jar >>

Then in your project’s installation script you’ll need to do something along the lines of

cp build/css/ /path/to/webserver/css/ cp build/js/ /path/to/webserver/js/ cp build/php/ path/to/php/config/include/directory/ sudo apache2ctl graceful

Note that it is necessary to restart Apache in order to reload the config file.

After running the build script, we just need to write this function for generating the full pathname.

All in all, this is a workable solution, but fairly awkward. Can we do better?

Run Time Version Discovery

Another solution would be to scan the directory to discover the name of the file (you’ll still need to use the same compile script above, but without the config file, and thus without the requirement of restarting your server after each change).

  If we were really going to use the above code, we would probably want to extend it to show preference for higher version numbers, which would make it is possible for (likely, actually, depending on how you are deploying your app) two version of a given file to cohabitant.

Another likely improvement would be to cache the versioned filenames at some level (perhaps using the Alternative PHP Cache), but doing so adds a layer of complexity when you want to update to a newer version of the filenames, which in the would likely end up being more complex than simply restarting Apache to reload the newest config settings.

Better Suggestions?

In the end, I’m not particularly pleased with either of these solutions, although they are both workable. My PHP background isn’t particularly deep, so there may be a standard PHP solution to this problem that I have simply overlooked.

(As a side note, I included the tags because Pygments seems to require them for properly highlighting PHP snippets.)

Hi folks. I’m Will aka @lethain.
If you’re looking to reach out to me, here are ways I help. If you’d like to get a email from me, subscribe to my weekly newsletter.

Источник

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