Displaying files in proper DATE order

Thanks in advance for any help out there…

I wrote this code so it displays images in a directory. The issue is with the new server running PHP as an Apache 2.0 Handler module it is not showing the files in proper time order… Using PHP Version 5.3.2-1 ubuntu4.17

This is the order it displays the files now:

FileName: http://www.domain1.com/articles/images/2014/HOUSE_layout.jpg
Size: 9.92 Kb
Date Created: Sat Jun 14, 2014 11:40:am

FileName: http://www.domain1.com/articles/images/2014/photo 4.JPG
Size: 731.28 Kb
Date Created: Sat Jun 14, 2014 11:46:am

FileName: http://www.domain1.com/articles/images/2014/photo 5.JPG
Size: 715.89 Kb
Date Created: Sat Jun 14, 2014 11:45:am

FileName: http://www.domain1.com/articles/images/2014/photo (2).JPG
Size: 108.74 Kb
Date Created: Sat Jun 14, 2014 11:41:am

FileName: http://www.domain1.com/articles/images/2014/photo 2.JPG
Size: 118.50 Kb
Date Created: Sat Jun 14, 2014 11:46:am

FileName: http://www.domain1.com/articles/images/2014/mega_milk.jpg
Size: 40.82 Kb
Date Created: Sat Jun 14, 2014 11:40:am

This is my code… It use to work great… Not sure why it is not displaying the files in order anymore?
[php] Current Directory Contain the
Following Images…

(Highlight the image link and ‘Copy & Paste’ - You want to select FROM < to >)



<?php
$dir = new DirectoryIterator( ‘/var/www/vhosts/domain1.com/httpdocs/articles/images/2014’ );
foreach($dir as $file )
{
if(!$file->isDot() && !$file->isDir()) {
echo “<font size=“2” face=“Verdana”>”;
echo “FileName: <font color=”#990000">http://www.domain1.com/articles/images/2014/".$file->getFilename()."
";
echo “Size: “.number_format(($file->getSize()/1024),2).” Kb
”;
echo “Date Created: “.date(“D M d, Y h:i:a”,$file->getCTime()).”

”;
echo “”;
}
}
?>[/php]

AGAIN!!! Thanks for any help…

Any ideas guys and gals? Would be much appreciated… Below is the whole page of code if that helps at all… It just will not display the files in the proper order of time created… (As shown in post above)

[php]

Sports Article System - Image upload
<META NAME="ROBOTS" CONTENT="NOINDEX">

<META NAME="ROBOTS" CONTENT="NOIMAGEINDEX">

<META NAME="ROBOTS" CONTENT="NOFOLLOW">

<meta name="robots" content="noindex,nofollow" /> 

 



Sports Articles Image Uploader for SThunder Submission

<?php echo "

"; echo " "; echo ""; echo " "; echo "
"; echo " "; echo ""; echo "
";

#form has been submitted
if($_POST[‘upload’])

#select file check
if($_POST[‘upload’]) {
if($_FILES[‘image’][‘name’] == “”)
{
#there’s no file name return an error
echo “


”;
echo “Please select a file to upload! - DIPPY\n”;

}
#we have a filename, continue
}

variable assign - File types and Upload directory to send files

$uploads = ‘/var/www/vhosts/domain1.com/httpdocs/articles/images/2014’;
$types_array = array(‘image/gif’,‘image/pjpeg’,‘image/x-png’);

#if(!in_array($_FILES[‘image’][‘type’], $types_array))
#{
#the type of the file is not in the list we want to allow

echo “That file type is not allowed!!! Unbelievable…\n”;

exit;

#}

move_uploaded_file($_FILES[‘image’][‘tmp_name’], $uploads.’/’.$_FILES[‘image’][‘name’]);?>






Current Directory Contain the
Following Images…

(Highlight the image link and ‘Copy & Paste’ - You want to select FROM < to >)



<?php
$dir = new DirectoryIterator( ‘/var/www/vhosts/domain1.com/httpdocs/articles/images/2014’ );
foreach($dir as $file )
{
if(!$file->isDot() && !$file->isDir()) {
echo “<font size=“2” face=“Verdana”>”;
echo “FileName: <font color=”#990000">http://www.domain1.com/articles/images/2014/".$file->getFilename()."
";
echo “Size: “.number_format(($file->getSize()/1024),2).” Kb
”;
echo “Date Created: “.date(“D M d, Y h:i:a”,$file->getCTime()).”

”;
echo “”;
}
}
?>




[/php]

Fixed the issue already but if anyone is interested here is the code that corrected that problem…

[php]

Sports Article System - Image upload
<META NAME="ROBOTS" CONTENT="NOINDEX">

<META NAME="ROBOTS" CONTENT="NOIMAGEINDEX">

<META NAME="ROBOTS" CONTENT="NOFOLLOW">

<meta name="robots" content="noindex,nofollow" /> 

 

Sports Articles Image Uploader for SThunder Submission

<?php echo "

"; echo " "; echo ""; echo " "; echo "
"; echo " "; echo ""; echo "
";

#form has been submitted
if($_POST[‘upload’])

#select file check
if($_POST[‘upload’]) {
if($_FILES[‘image’][‘name’] == “”)
{
#there’s no file name return an error
echo “


”;
echo “Please select a file to upload! - DIPPY\n”;

}
#we have a filename, continue
}

variable assign - File types and Upload directory to send files

$uploads = ‘/var/www/vhosts/your_domain.com/httpdocs/dir/path’;
$types_array = array(‘image/gif’,‘image/pjpeg’,‘image/x-png’);

#if(!in_array($_FILES[‘image’][‘type’], $types_array))
#{
#the type of the file is not in the list we want to allow

echo “That file type is not allowed MOM!!! Unbelievable…\n”;

exit;

#}

move_uploaded_file($_FILES[‘image’][‘tmp_name’], $uploads.’/’.$_FILES[‘image’][‘name’]);?>



Current Directory Contain the
Following Images…

(Highlight the
image link and ‘Copy & Paste’ - You want to select FROM
< to >
)




<?php
$newIterable = array();
$count = 0;
foreach(new DirectoryIterator(’/var/www/vhosts/your_domain.com/httpdocs/images/dir/path’) as $data)
{

					if(! $data->isDot() && ! $data->isDir())
					{
       	    			          if(!isset($newIterable[$data->getCTime()]))
       	    			          {
							$newIterable[$data->getCTime()] = array('name' => $data->getFilename(),'size' => $data->getSize(),'created' => $data->getCTime());
						}
       	    			                else
       	    			                {
							++$count;
							$newIterable[$data->getCTime() + $count] =  array('name' => $data->getFilename(),'size' => $data->getSize(),'created' => $data->getCTime());
						}
					 }
				}
														
				krsort($newIterable);

				#Use this line below if you would like to see the array results displayed
				/*?><pre><?php var_dump($newIterable);?></pre><?php */
														
				foreach($newIterable as $file)
				{
					echo "<font size=\"2\" face=\"Verdana\">";
					echo "FileName: <font color=\"#990000\"><b>http://www.your_domain.com/images/dir/path/" . $file['name'] . "</b></font><BR>";
					echo "Size: " . number_format(($file['size'] / 1024), 2) . " Kb<BR>";
					echo "Date Created: " . date("D M d, Y h:i:a", $file['created']) . "<BR><BR>";
					echo "</strong></font>";
				}
				?>
         </p></td>
				</tr>
			</table> <br /></td>
	</tr>
</table>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service