Advertisement
Andrewayaz

Upload

Dec 18th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2.  
  3. $findex = "upld";
  4.  
  5.  
  6. $newname = uniqid($findex . "_");
  7. // A list of permitted file extensions
  8. $allowed = array('png', 'jpg', 'gif','tiff' , 'pdf' , 'zip' , 'docx' , 'doc' , 'mp3' , 'avi' , 'mov' , 'mp4' , 'mkv' , 'zip' , 'rar');
  9.  
  10. if(isset($_FILES[$findex]) && $_FILES[$findex]['error'] == 0){
  11.  
  12.     $extension = pathinfo($_FILES[$findex]['name'], PATHINFO_EXTENSION);
  13.     $base = pathinfo($_FILES[$findex]['name'], PATHINFO_FILENAME);
  14.     $newname = $base . "_" . uniqid() . "." . $extension;
  15.  
  16.     /*if(!in_array(strtolower($extension), $allowed)){
  17.         echo '{"status":"error"}';
  18.         exit;
  19.     }
  20. */
  21.     if(move_uploaded_file($_FILES[$findex]['tmp_name'], 'uploads/'. $newname )){
  22.        
  23.         // add to picture list
  24.         // add pocture list id to bids table
  25.        
  26.        
  27.         echo '{"status":"success" , "newname" : "'.$newname.'"}';
  28.         exit;
  29.     }
  30. }
  31.  
  32. echo '{"status":"error"}';
  33. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement