so I have successfully uploaded the image file to the ftp server and the image file is shaped like an auto generated hash file name, so how do I make the file name I upload is the same as the image name?, because when it is saved to the database it is not hashed but the name the file is the same as the uploaded image, but on the ftp server when saving it the file name is shaped like a hash
example upload file in ftp server :
example controller :
$lampiran = Lampiran_tte::where('surat_tte_id', $surat->id);
if ($request->hasfile('lampiran_gambar')) {
$files = [];
foreach ($request->file('lampiran_gambar') as $file) {
if ($file->isValid()) {
$filename = $file->getClientOriginalName();
$file->store('/lampiranSurat', 'ftp') . '/' . $filename;
$files[] = [
'lampiran_gambar' => $filename,
];
}
}
$gambar = '';
foreach ($files as $value) {
$gambar .= $value['lampiran_gambar'].'#';
}
$gambar = substr($gambar, 0, -1);
$lampiran->update([
'isi_lampiran' => $request->isi_lampiran,
'lampiran_gambar' => $gambar,
'update_by' => Auth::user()->name,
]);
}
if it is already stored in the database, the image file name matches the image file name that was uploaded example in database :
CodePudding user response:
The store()
function is generating the unique ID value for the file. Use the storeAs()
function instead which allows you to specify a filename of your choice.
$file->storeAs('/lampiranSurat', $filename, 'ftp');