laravel file upload
Hi when i upload a image, temp file only uploaded in the directory ,that image wasn't upload at that same time image file name also has changed.
@pandiyan and can you please share the code? It is hard to say this way.
@nakov
if($request->hasfile('custom_attribute_sizechart_image'))
{
$custom_attribute_sizechart_image=$request->file('custom_attribute_sizechart_image');
$filename = $custom_attribute_sizechart_image->getClientOriginalName();
@mkdir(public_path("/images/.$custom_attribute_category_id."));
$custom_attribute_sizechart_image->move(public_path("/images/.$custom_attribute_category_id", $filename));
}
else
{
dd('failed to upload');
}
and the file in directory was php6801.tmp
@nakov Thanks its working fine.but the file name is not correct. it generate random number
@pandiyan you can try this:
$filename = $custom_attribute_sizechart_image->getClientOriginalName();
dd($filename);
and it will tell you which filename is being uploaded. Original name is used here.
@nakov your right, but i am using this code
$custom_attribute_sizechart_image=$request->file('custom_attribute_sizechart_image');
$filename = $custom_attribute_sizechart_image->getClientOriginalName();
$path="/images/$custom_attribute_category_id";
if(!Storage::disk('public')->put($path, $custom_attribute_sizechart_image)) {
when i use $filename upload not working
@pandiyan then make your path this:
$filename = $custom_attribute_sizechart_image->getClientOriginalName();
$path="/images/$custom_attribute_category_id/" . $filename;
if(!Storage::disk('public')->put($path, $custom_attribute_sizechart_image)) {
..
@nakov this code for create new folder as filename,but file name not changed
@pandiyan try one of this:
$path="/images/$custom_attribute_category_id";
Storage::disk('public')->put($path, file_get_contents($custom_attribute_sizechart_image));
or
$path="/images/$custom_attribute_category_id";
Storage::disk('public')->putFile($path, $custom_attribute_sizechart_image);
@nakov 1st option not working and 2nd option working same like previous.
@pandiyan okay friend, this is what I use and it works just fine:
$file = $request->file('custom_attribute_sizechart_image');
$directory="/images/$custom_attribute_category_id";
$filename = $file->getClientOriginalName() . '.' . $file->getClientOriginalExtension();
$file->move(public_path() . $directory, $filename);
thank u very much @nakov .finaly this code work.
$custom_attribute_sizechart_image=$request->file('custom_attribute_sizechart_image');
$path="/images/$custom_attribute_category_id";
$filename = $custom_attribute_sizechart_image->getClientOriginalName();
// .'.'.$custom_attribute_sizechart_image->getClientOriginalExtension();
$custom_attribute_sizechart_image->move(public_path() . $path, $filename);
Please or to participate in this conversation.