-1

I'm have using Php, MongoDb and GridFs to store and retrieve files. It works fine for images, but I want to store files with docx, pdf, csv and etc. extensions. Here is my code:

$ext = $this->getFileExt($_FILES["news_attachment"]["name"]);
                switch ($ext) {
                    case 'pdf':
                        $mimeType = 'application/pdf';
                        break;
                    case 'doc':
                        $mimeType = 'application/msword';
                        break;
                    case 'docx':
                        $mimeType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
                        break;
                    case 'xls':
                        $mimeType = 'application/vnd.ms-excel';
                        break;
                    case 'xlsx':
                        $mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                        break;
                    case 'ppt':
                        $mimeType = 'application/x-mspowerpoint';
                        break;
                    case 'pptx':
                        $mimeType = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
                        break;
                    case 'csv':
                        $mimeType = 'text/csv';
                        break;
                    case 'txt':
                        $mimeType = 'text/plain';
                        break;
                    default:
                    $mimeType='application/pdf';
                }
                $gridFs = $this->getGridFs();
                $fileData = array(
                    "filename" => microtime(true) . "." . $ext,
                    "contentType" => $mimeType);
                $_id = $gridFs->storeUpload("news_attachment", $fileData);

But I get the same error message Message: error setting up file: . I've checked the file size is 78kb, $fileData is ok also. So, my question is - What else can caused this error?

2 Answers2

0

Would you not be supplying the same argument when trying to upload:

$gridFs->storeUpload($_FILES["news_attachment"]["name"], 

or possibly

$gridFs->storeUpload($_FILES["news_attachment"]["tmp_name"], 
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
0

I just need to add check for error if(!empty($_FILES["news_attachment"]) && $_FILES["news_attachment"]["error"] == 0){ save file}