I have one form which contains one file upload.
Form Id is "upload_form"
<input type="file" id="image" name="image"/>
Using javascript onclick function and ajax to pass the image to the controller.
Ajax fn:
$.ajax({
url: 'UploadImage',
data:new FormData($("#upload_form")[0]),
type: "post",
dataType:"JSON",
async:false,
success: function (data) {
console.log(data);
}
});
}
Routes:
Routes::post('UploadImage','UploadController@Upload');
UploadController:
public function Upload()
{
$file = Input::file('image');
$tmpFilePath = '/temp/uploads/';
$tmpFileName = time() . '-' . $file->getClientOriginalName();
$path = $tmpFilePath.$tmpFileName;
$data_file = $file->move(public_path() . $tmpFilePath, $tmpFileName);
// Error for move() and getClientOriginalName() functions.
}
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/21QOh40
via IFTTT
Aucun commentaire:
Enregistrer un commentaire