Cannot upload files from frontend
Permalink 1 user found helpful
Hi guys
I'm building a custom package which needs to upload files from frontend. I cannot use Front end file uploader or any other file block. need to custom code it as per the requirement.
Here is my code:
It doesn't upload the file. Am I doing anything wrong? Please help me. Its urgent!
Rony
I'm building a custom package which needs to upload files from frontend. I cannot use Front end file uploader or any other file block. need to custom code it as per the requirement.
Here is my code:
Loader::library('file/importer'); $fi = new FileImporter(); $resp = $fi->import($_FILES['projDocuments']['tmp_name'], '', ''); if (!($resp instanceof FileVersion)) { switch($resp) { case FileImporter::E_FILE_INVALID_EXTENSION: $this->error->add(t('Invalid file extension')); break; case FileImporter::E_FILE_INVALID: $this->error->add(t('Invalid file.')); break; } } else { $projDocuments = $resp->getFileID(); Loader::model('file_set');
Viewing 15 lines of 21 lines. View entire code block.
It doesn't upload the file. Am I doing anything wrong? Please help me. Its urgent!
Rony
Thank you so much. Its very helpful. Somewhere I read that if I don't want to rename the file or its a fresh upload, not overwriting any existing files, then simply leave the other 2 parameters blank. So I was not sure to should be false rather blank. Thank you so much.
Rony
Rony
Ah most likely that whatever you read actually meant to completely omit the 2nd and 3rd parameters, as opposed to setting them to be an empty string. You should be able to simply pass in the first parameter like so:
Glad you got it sorted out!
$resp = $fi->import($_FILES['projDocuments']['tmp_name']);
Glad you got it sorted out!
Would you be willing to share your code, or an outline of how you achieved this?
http://www.concrete5.org/documentation/developers/files/importers/...
https://github.com/concrete5/concrete5/blob/123948b89480ceaabbcfb2c0...