Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ImageController extends BaseController {
- public function getUploadImage()
- {
- $images = Images::all();
- return View::make('admincp/image')
- ->with('images', $images);;
- }
- public function postUploadImage()
- {
- $images = Images::all();
- $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
- $string = 'image';
- for ($i = 0; $i < $random_string_length; $i++) {
- $string .= $characters[rand(0, strlen($characters) - 1)];
- }
- $uniqueid = $string;
- $complete = false;
- while($complete = false)
- {
- if(Images::where('imagesrc', '=', $uniqueid)->firstOrFail())
- {
- $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
- $string = 'image';
- for ($i = 0; $i < $random_string_length; $i++) {
- $string .= $characters[rand(0, strlen($characters) - 1)];
- }
- $complete = false;
- }
- else
- {
- $complete = true;
- }
- }
- $target_dir = "uploads/";
- $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
- $uploadOk = 1;
- $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
- // Check if image file is a actual image or fake image
- if(isset($_POST["submit"])) {
- $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
- if($check !== false) {
- echo "File is an image - " . $check["mime"] . ".";
- $uploadOk = 1;
- } else {
- echo "File is not an image.";
- $uploadOk = 0;
- }
- }
- $imagename = Input::get('imagename');
- $imagesrc = Input::get('imagesrc');
- Images::create(array(
- 'uniqueid' => $uniqueid,
- 'imagename' => $imagename,
- 'imagesrc' => $imagesrc
- ));
- return URL::route('admin-upload-image');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement