Dropzone.js rename after upload success I want my file name become unqiue therefore i can pass the file name to controller and delete the file by name.
But i tried it a lot of way its doesnt work. Any idea how can i change the file name??
when it upload success
myDropzone.on("success", function(response) {
let newName = response.xhr.response;
myDropzone.on("renameFile", function(response) {
return newName;
});
});
You should probably change the name of the file on the server and not in your JS code.
@bobbybouwmann I change it on server and i return the new file name. Now i want to rename the uploaded file name to the name i return.
public function updateImg(Request $request){
$image = $request->file('file');
$imageName = time().'.'.$image->extension();
$image->move(public_path('img/product/'),$imageName);
return response()->json($imageName);
}
are you trying to rename the file in the client computer? That would never be allowed.
@bobbybouwmann I tried this but its didnt work. Not sure where the file have been saved. Can i know what the different between this two??
$image->storeAs(public_path('img/product/'), $imageName);
move() is correct as far as I am concerned
@snapey No. I only need to rename the file have been uploaded in the dropzone.
so what wrong? what is not working
ok, so move() is ok, but you have to tell it where the file is now, and where you want it to be. Bobby is correct, storeAs is easier to use
So if this did not work, is public_path set correctly
open tinker and type public_path('img/product/')
Please sign in or create an account to participate in this conversation.