EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 651

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
About file uploading and downloading 651
array_push($files, array('./images/'.$file, filectime('./images/
'.$file)));
}
usort($files, sorter);
if (count($files) > $MAXIMUM_FILE_COUNT) {
$files_to_delete = array_splice($files, 0, count($files) -
$MAXIMUM_FILE_COUNT);
for ($i = 0; $i < count($files_to_delete); $i++) {
unlink($files_to_delete[$i][0]);
}
}
print_r($files);
closedir($directory);
function sorter($a, $b) {
if ($a[1] == $b[1]) {
return 0;
} else {
return ($a[1] < $b[1]) ? -1 : 1;
}
}
?>
This PHP code first defines two constant variables: $MAXIMUM_FILESIZE and
$MAXIMUM_FILE_COUNT. These variables dictate the maximum size (in kilobytes) of an
image being uploaded to the server (200KB), as well as how many recently uploaded files
can be kept in the images folder (10). If the file size of the image currently being uploaded
is less than or equal to the value of
$MAXIMUM_FILESIZE, the image is moved to the
temporary folder.
Next, the file type of the uploaded file is checked to ensure that the image is a JPEG, GIF,
or PNG. If the image is a compatible image type, the image is copied from the temporary
folder to the images folder. If the uploaded file wasnt one of the allowed image types, it is
deleted from the file system.
Next, a directory listing of the image folder is created and looped over using a while loop.
Each file in the images folder is added to an array and then sorted. If the current number
of files in the images folder is greater than the value of
$MAXIMUM_FILE_COUNT, files are
deleted until there are only
$MAXIMUM_FILE_COUNT images remaining. This prevents the
images folder from growing to an unmanageable size, as there can be only 10 images in
the folder at one time, and each image can only be 200KB or smaller (or roughly 2 MB of
images at any time).
3. Save your changes to the PHP document.
4. Upload the SWF, HTML, and PHP files to your web server.

Table of Contents

Related product manuals