jeremihza's avatar

need to upload doc file..help in modifying controller

class ImageController extends Controller { // public function index(){ $files = FileUpload::all();

    return ['files'=> $files];
}
public function store(Request $request)
{
    if($request->get('image'))
       {
          $image = $request->get('image');
          $name = time().'.' . explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
          \Image::make($request->get('image'))->save(public_path('images/').$name);
        }
    $image = new FileUpload();
    $image->image_name = $name;
    $image->save();

    return response()->json(['success' => 'You have successfully up loaded an image'], 200);     
}

public function download($fileName){
     $file_path = public_path('images/'. $fileName);
     $header = array('Content-Type' => , 'application/pdf');
     return response()->download($file_path);
}

}
0 likes
3 replies
jeremihza's avatar

i need it to accept uploading doc and pdf thats my challenge

tykus's avatar

The process is the same other than you will not use Intervention; the UploadedFile class has its own store method which takes a path, e.g.:

$request->file('doc')->store(public_path('docs'));

// or to specify your own filename

$request->file('doc')->storeAs(public_path('docs'), $name);

Please or to participate in this conversation.