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 wasn’t 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.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...