As title really, does anyone know of (or could write?) a php file which
in a directory of .jpg files display the most recent added to that
/dir?
Can anyone help? 10 7238
On 6 Feb 2005 09:36:21 -0800, ro*********@gmail.com wrote: As title really, does anyone know of (or could write?) a php file which in a directory of .jpg files display the most recent added to that /dir?
Can anyone help?
<?php
$ctime = 0;
foreach (glob('*.jpg') as $file)
{
if ($ctime > filectime($file))
{
$match = $file;
$ctime = filectime($file);
}
}
print $file;
?>
--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
I think i'll have to elaborate on my original question a little
further, when I say display I mean literally display the image in an
img src HTML tag.
Cheers
On 6 Feb 2005 11:13:24 -0800, "arepeejee" <ro*********@gmail.com> wrote: I think i'll have to elaborate on my original question a little further, when I say display I mean literally display the image in an img src HTML tag.
Well then, instead of:
print $file;
... then ...
print '<img src="' . htmlentities($file) . '" alt="whatever">';
--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Hmm, I still cant get it to work. It doesnt appear to like the $ in
line16.
arepeejee wrote: I think i'll have to elaborate on my original question a little further, when I say display I mean literally display the image in an img src HTML tag.
With the code from Andy you get the file name. What else do you need?
Matthias
Well, ive got a random php script (below) which I can literally have it
as an image:
<img src=http://whatever.com/random.php>
and I want a similar thing to instead display the last updated image
from the dir.
[code:
<?php
$fileList = array();
$folder = ".";
$handle = opendir($folder);
while (
false !== ( $file = readdir($handle) )
) {
if (
substr($file, -4) == ".gif" ||
substr($file, -4) == ".jpg"
) {
$fileList[count($fileList)] = $file;
}
}
closedir($handle);
$randNum = rand( 0, (sizeOf($fileList) -1) );
if (
substr($fileList[$randNum], -4) == ".gif"
) {
header ("Content-type: image/gif");
} elseif (
substr($fileList[$randNum], -4) == ".jpg"
) {
header ("Content-type: image/jpeg");
}
readfile($fileList[$randNum]);
?>
[end code]
On 6 Feb 2005 11:40:01 -0800, "arepeejee" <ro*********@gmail.com> wrote: Hmm, I still cant get it to work. It doesnt appear to like the $ in line16.
What line 16? I posted 13 lines of code.
--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
How odd, thats what it said (and still says) here
I have managed to find a solution, and for anyoen who may want
something similar, thanks to all above:
<?php
$path = './';
// with trailing slash, for images in other dirs: $path =
'./foldername/'
unset($fpath, $time, $time, $ext, $type);
$type = array
(
// ---------------------------
// ext mime type
'png' => 'image/png',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'gif' => 'image/gif',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
);
if ( is_dir($path) )
{
if ( $dh = @opendir($path) )
{
while ( ($file = readdir($dh) ) !== false )
{
if ( $file == '.' or $file == '..' )
{
next;
}
// echo $file . " :";
// Var with full path+name
$fpath = $path.$file;
// Skip if dir
if ( is_dir($fpath) )
{
next;
}
// echo $fpath . " ::";
// Get file extension
$ext = substr ( $fpath, strrpos($fpath, '.') + 1 );
// Should get most recent file
if ( isset($type[$ext]) )
{
$mtime = filemtime($fpath);
if ( $mtime > $time )
{
$img = array ( 'fpath' => $fpath, 'name' => $file, 'ext' => $ext
);
$time = $mtime;
}
}
}
}
closedir($dh);
if ( $img['name'] != '' )
{
if ( $fh = @fopen($img['fpath'], "rb") )
{
@header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT'); //
Date in the past
@header( 'Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); //
always modified
@header( 'Cache-Control: no-cache, must-revalidate'); //
HTTP/1.1
@header( 'Pragma: no-cache'); //
HTTP/1.0
@header( 'Content-Disposition: inline; filename="'.$img['name'].'"'
);
@header( 'Content-transfer-encoding: binary');
@header( 'Content-Length: '.(string)(filesize($img['fpath'])) );
@header( 'Content-Type: '.$type[ $img['ext'] ] );
// @header( 'Content-Type: '.$type[ $img['ext'] ] );
// @header( 'Content-Disposition: inline;
filename="'.$img['name'].'"' );
// @header( 'Content-Length: '.(string)(filesize($img['fpath'])) );
while ( ! feof($fh) )
{
echo fread($fh, 8192);
}
@fclose($fh);
exit;
}
}
}
$filedata =
base64_decode('R0lGODlhAQABAIAAAMDAwAAAACH5BAEAAAA ALAAAAAABAAEAAAICRAEAOw==');
$filesize = strlen($filedata);
@header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date
in the past
@header( 'Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); //
always modified
@header( 'Cache-Control: no-cache, must-revalidate'); //
HTTP/1.1
@header( 'Pragma: no-cache'); //
HTTP/1.0
@header( 'Content-disposition: inline; filename=blank.gif');
@header( 'Content-transfer-encoding: binary');
@header( "Content-Length: $filesize");
@header( 'Content-type: image/gif');
echo $filedata;
exit;
?> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JPM III |
last post by:
I wrote a PHP script that allows me to post HTML entries to files on my
server without going through FTP, yadda yadda. It works fine, and last night
it updated both files properly.
Today, it...
|
by: Fred |
last post by:
Hi,
I'm sure there are a bunch of them, but googling just returned
full-fledged CMS that require a DBMS and generate dynamic pages.
I'd just like a script that would
1. look in a directory...
|
by: Amanda |
last post by:
Hi, hope you can help me with this one.
If I want to get the date a page has been last modified, I can do something
like ..
document.write("<b>Last updated: "+document.lastModified+"</b>");
...
|
by: Scott Baxter |
last post by:
Hello,
I got the following scripts to upload files to my directories
I call insert.htm
Browse for a file, then click 'submit'
It works for small files, and for a small .mdb (access file)
|
by: brian.digipimp |
last post by:
So I wrote this upload script and I keep getting errors and can't get
it to work. I'm running ubuntu linux and here is my code:
<html>
<head>
<title>Upload</title>
</head>
<body>
<?php
|
by: pbd22 |
last post by:
hi.
i am having probs understanding how to grab a file being uploaded from
a remote client. i am using hidden input fields for upload such as:
<input id="my_file_element" type="file"...
|
by: Lastknight |
last post by:
hi all,
i have seen a program from web that is used to upload a file from particular directory..
My problem is that they have mentioned some file directory name in the program but when i am running...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click...
|
by: jeddiki |
last post by:
Hi,
As I am in Turkey at present, I can not see vidoes on
youtube. So I have tried a few proxies but keep finding them slow or
not working.
So I have installed myphpProxy on my server under...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |