Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function store(Request $request)
- {
- $target_dir = public_path('uploading/');
- if($image = $request->hasFile('img')) {
- $imageFileType = strtolower($_FILES["img"]["type"]);
- $uploadOk = 1;
- $imageFileType = explode('/', $imageFileType)[1];
- $target_file_name = md5(date('YmdHis') . basename($_FILES["img"]["name"]));
- $target_file = $target_dir . $target_file_name . '.' . $imageFileType;
- $check = getimagesize($_FILES["img"]["tmp_name"]);
- if ($check != false) {
- $uploadOk = 1;
- } else {
- $uploadOk = 0;
- }
- if ($imageFileType != "svg" && $imageFileType != "png" && $imageFileType != "jpeg"
- && $imageFileType != "gif") {
- echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
- $uploadOk = 0;
- }
- if ($uploadOk == 0) {
- echo "Sorry, your file was not uploaded.";
- } else {
- if (move_uploaded_file($_FILES["img"]["tmp_name"], $target_file)) {
- //Service::create(['title'=>$request->title, 'description'=>'l', 'image'=>$target_file_name . '.' . $imageFileType]);
- } else {
- echo "Sorry, there was an error uploading your file.";
- }
- }
- $title = $request->title;
- $description = $request->description;
- Service::create(['title'=>$title,'description'=>$description,'image'=>$target_file_name . '.' . $imageFileType]);
- }
- }
Add Comment
Please, Sign In to add comment