Advertisement
amereservant

Untitled

Feb 26th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2. /* CODE FOR HANDLING PICUP PHOTO UPLOADS */
  3. require 'config.php';
  4.  
  5. // Include File Upload Class
  6. require BASEPATH .'_'. DS .'upload.class.php';
  7.  
  8. if( !isset($_FILES['picup-photo']) ) {
  9.     die( json_encode( array('error' => true, 'key' => key($_FILES)) ) );
  10. }
  11.  
  12. $upload = new fileUpload();
  13.  
  14. $upload->set_attrs( array(
  15.     'rename_file' => true,
  16.     'upload_dir'  => BASEPATH . UPLOAD_DIR . DS
  17. ));
  18.  
  19. // Set accepted file types
  20. $upload->setFileTypes( array('jpg', 'png', 'gif') );
  21.  
  22. // Try processing uploaded file
  23. $result = $upload->upload($_FILES);
  24.  
  25. if( !$result ) {
  26.     // Check for error messages
  27.     if( count($upload->message) < 1 )
  28.         die( json_encode( array('error' => true, 'msg' => implode('<br>', $upload->message)) ) );
  29.  
  30.     // If no error messages, we'll just let them know it failed for some undetermined reason...
  31.     die( json_encode( array('error' => true, 'msg' => 'Photo upload failed for unkown reason!') ) );
  32. }
  33.  
  34. die( json_encode( array('error' => false, 'filename' => $upload->thefile) ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement