eskiesirius's avatar

Update Uploaded File Approach

Hi! I know this is a very basic question but still im looking for a neat approach when handling uploaded file.. creating a record with file is very easy since you will just directly store the file but how about updating the file with these scenarios:

  • How to determine that the file has been removed?
  • How to determine that there are no changes in the uploaded file?
  • How to determine that the file is being replaced?
0 likes
4 replies
eskiesirius's avatar

@Sergiu17 what i mean what should be the logic on how to update uploaded files.. my current logic is that there will be two fields: file field and the file path field, so if file path and file field is null it means i need to remove the file that is associated with the record. If the file path is not null then no changes in the uploaded file, if the file path is null and file field is not then it means i need to replace the uploaded file

Sergiu17's avatar

@eskiesirius

// if file path and file field is null it means i need to remove the file that is associated with the record
if(!$request->has('file-path') && !$request->has('file')) {
  // remove file
}
// if the file path is null and file field is not then it means i need to replace the uploaded file
else if(!$request->has('file-path') && $request->has('file')) {
	// delete the existing file
	// save new file
}

something like this I guess

eskiesirius's avatar

@Sergiu17 yeah that is my current logic.. is there any thing you can suggest about this kind of flow?

Please or to participate in this conversation.