Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <?php
  2.  
  3. class ImageController extends BaseController {
  4.  
  5. public function getUploadImage()
  6. {
  7. $images = Images::all();
  8. return View::make('admincp/image')
  9. ->with('images', $images);;
  10. }
  11. public function postUploadImage()
  12. {
  13.  
  14. $images = Images::all();
  15. $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
  16. $string = 'image';
  17. for ($i = 0; $i < $random_string_length; $i++) {
  18. $string .= $characters[rand(0, strlen($characters) - 1)];
  19. }
  20. $uniqueid = $string;
  21. $complete = false;
  22. while($complete = false)
  23. {
  24. if(Images::where('imagesrc', '=', $uniqueid)->firstOrFail())
  25. {
  26. $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
  27. $string = 'image';
  28. for ($i = 0; $i < $random_string_length; $i++) {
  29. $string .= $characters[rand(0, strlen($characters) - 1)];
  30. }
  31. $complete = false;
  32. }
  33. else
  34. {
  35. $complete = true;
  36. }
  37. }
  38. $target_dir = "uploads/";
  39. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  40. $uploadOk = 1;
  41. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  42. // Check if image file is a actual image or fake image
  43. if(isset($_POST["submit"])) {
  44. $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  45. if($check !== false) {
  46. echo "File is an image - " . $check["mime"] . ".";
  47. $uploadOk = 1;
  48. } else {
  49. echo "File is not an image.";
  50. $uploadOk = 0;
  51. }
  52. }
  53. $imagename = Input::get('imagename');
  54. $imagesrc = Input::get('imagesrc');
  55.  
  56. Images::create(array(
  57. 'uniqueid' => $uniqueid,
  58. 'imagename' => $imagename,
  59. 'imagesrc' => $imagesrc
  60. ));
  61. return URL::route('admin-upload-image');
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement