Hi I'm trying to upload an image with Laravel 5
Function is:
$file_name = '';
//validation of image before uploading and saving
if( Input::hasFile('img') && Input::file('img')->isValid() ){
$file = Input::file('img'); //creating an object
$file_name = str_random(30) . '.' . $file->getClientOriginalExtension(); //randon str name to img file with the ext of the original file
$file->move( public_path() . '\assets\img', $file_name);
}
form: multipart/form-data
input: input type="file" name="img"
The problem is that there's always an empty value in $file_name