PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Matt Belanger   Image Upload   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Usage Example
Class: Image Upload
Handle and process uploaded image files
Author: By
Last change:
Date: 16 years ago
Size: 1,766 bytes
 

Contents

Class file image Download
<?php

 
include('ImageUploader.php');
 
 
$sizes = array (
   
'full' => array(640,480),
   
'thumb' => array(150, 112)
  );
 
  if (isset(
$_FILES['image'])) {
   
$img = new ImageUploader($_FILES['image'], $sizes, 'images', 'test.gif');
    if (
$img->getStatus() == ImageUploader::CAN_CONTINUE) {
     
$img->saveFiles();
    }
  }

?>

<html>
<head>
<title>Image Uploader Demo</title>
</head>
<body>

<?php
 
if ($img instanceof ImageUploader) {
    switch(
$img->getStatus()) {
      case
ImageUploader::SUCCESS:
        print
'<span style="color:#FF0000">Image Uploaded Successfully</span>';
        break;
      case
ImageUploader::INVALID_FILE_TYPE:
        print
'<span style="color:#FF0000">Invalid File Type</span>';
        break;
      case
ImageUploader::UNABLE_TO_CREATE_IMG:
        print
'<span style="color:#FF0000">Images could not be saved</span>';
        break;
      case
ImageUploader::INVALID_SIZES:
        print
'<span style="color:#FF0000">Invalid target sizes</span>';
        break;
      case
ImageUploader::NO_WRITE_PERMISSIONS:
        print
'<span style="color:#FF0000">Cannot write to target directory</span>';
        break;
      case
ImageUploader::FILE_SAVE_ERROR:
        print
'<span style="color:#FF0000">Images could not be saved</span>';
        break;
    }
    print
'<br />';
    if (
$img->getStatus() == ImageUploader::SUCCESS) {
     
$files = $img->getFilenames();
      foreach (
$files as $file) {
        print
"<img src='$file' /><br />";
      }
    }
  }
?>
<form method="POST" action="index.php" enctype="multipart/form-data">
  <input type="file" name="image" />
  <br />
  <input type="submit" value="Load Images" />
</form>

</body>
</html>