vue-file-agent
vue-file-agent copied to clipboard
Folder creation?
Is there a way to create folders? Or am I missing something?
Thanks.
No, this is a UI component for web where folder or file cannot be created on the local file system.
But it would be a good feature to support folder icons along with other file types for preloaded fileRecords - where this component will be used in a web file manager (maybe that’s what you’re trying to achieve).
Is there a way to create folders? Or am I missing something?
to create folder in upload folder with some posted data you can do...
1st - in template add
<button :disabled="!fileRecordsForUpload.length" @click="uploadFiles(customerId)">
Upload {{ fileRecordsForUpload.length }} files
</button>`
2nd - in script add new method
uploadFiles: function(id) {
this.$refs.vueFileAgent
.upload(
this.uploadUrl,
this.uploadHeaders,
this.fileRecordsForUpload,
function createFormData(fileData) {
var formData = new FormData();
formData.append("id", id);
formData.append("file", fileData.file);
return formData;
}
)}
3rd - in server side php change upload function like below
add this code to "public function handle" just before $response..... line
$folder = (isset($_POST['id']))? $_POST['id']:'';
if($folder != ''){
$this->uploadDir=$this->uploadDir.DIRECTORY_SEPARATOR.$folder;
}
than
public function handleUpload($uploadedFile,$folder){
// $filename = md5(microtime().$uploadedFile['name'].$uploadedFile['tmp_name']); // create a unique name
$filename = $uploadedFile['name']; // or use the file name from client
if($folder != ''){
$this->uploadDir=$this->uploadDir.'\\'.$folder;
if (!file_exists($this->uploadDir)) {
mkdir($this->uploadDir, 0755, true);
}
}
move_uploaded_file($uploadedFile['tmp_name'], $this->uploadDir.DIRECTORY_SEPARATOR.$filename);
return ['my_key' => $filename]; // you can send any arbitrary data to client which will be saved in fileRecord.upload key in client, and will be sent back to server at update/delete request
}
basiccaly i add customer id to button click function than add this field to new formdata with existing file data and use this info to create subfolder at upload folder.
i try to pass this field as props data which is coming from parent component but i got undefined when i use in create new formdata function.
@drascom I'm sorry I don't understand your question. Can you format your question in a way that can be easily understood.
@safrazik it was not question just try to show the way creating sub folder with posted data while uploading file to @avpavp great script by the way thank you...