When trying to upload an XML file in Codeigniter. I am working with eFax, trying to set up Inbound Fax Delivery: Enabling XML Posting. I am getting the following error anytime I do a test post using their Sample.xml file they have provided:
The filetype you are attempting to upload is not allowed.
Other documents will upload fine. In my upload config, xml is set in the options for allowed_types:
$config['allowed_types'] = 'txt|xml';
Why does Codeigniter not allow the eFax XML document type?
I've figured out why this was happening. By default, the MIME type was not set in Codeigniter's mimes.php config file. I needed to add an array of multiple MIME types for the xml MIME. Specifically, I needed to add application/xml.
So in /application/config/mimes.php I changed this line:
'xml' => 'text/xml',
To this (converting the xml option to an array):
'xml' => array('text/xml', 'application/xml'),
That fixed the problem right away.
this is the one I use:
'xml' => array('application/xml', 'text/xml', 'text/plain'),
NOTE: paste it in /application/config/mimes.php
Related
My client is using Joomla 3.7.2 and they are using the Zoo component by YOOTheme. They have created an App I believe it's called in jargon and they've added a property (element) where you can download a file.
The App is an article type app and they've used the default download element. I added the permissions to upload certain files and I've uploaded a VCF file (a vCard file).
The problem occurs when I download that file. Joomla seems to add the Content-Type: 'text/x-vcalendar'. This should be 'text/x-vcard'. I have no idea where to change this.
I have added this mime-type to my .htaccess, so when I directly link to the file, apache does send the right content type header. Therefor I know that the problem lies in either joomla or a PHP function that returns the wrong mime type.
Where do I change the mime-type for these files?
I finally found it. There's a function in the file: /administrator/components/com_zoo/framework/helpers/filesystem.php
Within this file there's a function called getMimeMapping. In it is an array with all the file extensions and mime types used per extension:
$mimes['vcf'][] = 'text/x-vcalendar';
$mimes['vcs'][] = 'text/x-vcalendar';
$mimes['vct'][] = 'text/x-vcard';
So apparently if I use the extension vct, it will output the correct Content-Type.
How can I export data from a CakePHP 2.4 app as KML, not just XML and JSON?
This is what I've been trying:
1: I created a simple controller action, download, to find all data in my model:
$this->set('posts', $this->Post->find('all'));
2: I addeded the file type in routes.php:
Router::parseExtensions('json', 'xml', 'kml', 'csv');
3: I created a folder for my data view file type:
/app/View/Post/kml
4: I created a view, download.ctp, which manually echos out the XML tags for the KML file.
Now comes the problem: When I place this view file under /app/View/Post/xml, visiting /posts/download.xml creates a valid KML document I can open in Google Earth, albeit with an .XML extension. When I place the file under /app/View/Post/kml, and visit /posts/download.kml, it throws an error: View file "/home/public/app/View/Themed/Cakestrap/Posts/download.ctp" is missing.
I tried copying my view to the above location, but that just echos the XML into my standard layout. What's the proper way to create data views for filetypes other than XML and JSON?
Saddly KML does not have a mime type recognized in servers vide Google. So when you add it to Router::ParseExtensions(...) Cake can't see that extension and won't try to access your download.ctp inside kml folder.
You have two alternatives to setup this to work:
Change server settings in order to it recognize the extension Google Doc.
Try to call render manually like this:
<?php
$this->response->type("application/vnd.google-earth.kml+xml");
$this->render('kml/download.ctp', 'xml');
I have a file upload function in my Symfony2 project and I would like to validate that the uploaded file is a .tex file format => LaTex file.
For text/html, I am using:
$metadata->addPropertyConstraint('file', new Assert\File(array(
'maxSize' => '100000k',
'mimeTypes' => array("text/html"),
'mimeTypesMessage' => 'Please upload a valid HTM/HTML File',
)));
I am trying:
$metadata->addPropertyConstraint('file', new Assert\File(array(
'maxSize' => '100000k',
'mimeTypes' => array(
'text/html',
'application/x-tex',
'application/x-latex'
),
'mimeTypesMessage' => 'Please upload a valid HTM/HTML/TEX File',
)));
But as soon as I am uploading a .tex file, I am getting the message:
Please upload a valid HTM/HTML/TEX File.
How can I add Tex file also here? Thank you.
I think that the same principles of image validation can be applied here. It's unreliable to trust mime-type since user could plant php executable within image/jpeg.
For the images this can be verified by using getimagesize() function. As for the LaTeX you would need some 3rd-party lib what will try to open uploaded file and throw the exception on error (invalid file format, invalid expression, etc...).
Maybe this one: PHPLatex?
Also, which mime-type did you get when you tried uploading file? (#Ahmed's idea)
Unless the submitting client 'knows' that tex files are registered as application/x-tex I believe that the client won't sent then as such.
Can you search for the \documentclass directive within the stream?
Alternatively if you are in control of the client machines, e.g. at work or university, can you get the mime types registered on them?
I think you've to use the application/x-latex mime-type.
I am trying to make a download action that downloads a Word doc generated in the 'download' controller using PHPDOCX. So far PHPDOCX is able to save the desired .docx file in the correct folder, but something goes wrong when I try to download it. Since Media Views were deprecated, I must use the CakeResponse file method as suggested in the CakePHP 2.x Cookbook:
// In the controller:
$this->response->file($file['path'], array('download' => true, 'name' => $filename));
return $this->response;
I was able to use this method for to export an RTF with no problem (the RTF was generated using PHPRTFLite), but when I use the method for a .docx file using PHPDOCX I receive the following error in Firefox:
The character encoding declaration of the HTML document was not found
when prescanning the first 1024 bytes of the file. When viewed in a
differently-configured browser, this page will reload automatically.
The encoding declaration needs to be moved to be within the first 1024
bytes of the file.
I would like to use a document generator that accepts HTML, which is why I chose PHPDOCX. Considering the above error, I set off to define the headers and content-type using the following method:
$this->response->header(array('Content-type'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.document'));
But I still receive the same error in CakePHP:
The requested file APP/files/info_sheets/filename.docx was not found or not readable
One thing I was thinking is that PHPDOCX sends many errors when it generates the document and this is interfering with the Mime-type or encoding. But according to the 2.x Cookbook:
Headers are not sent when CakeResponse::header() is called either.
They are just buffered until the response is actually sent.
Another idea is that I need to set the character encoding in the header right after the content-type:
$this->response->header(array('Content-type'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8'));
But this results in garbled text.
Does anyone have any ideas how to resolve this? The "download.ctp" view file is currently blank. Please let me know if you need additional information about this issue.
Thanks!
Chris
First of all, you might try to disable autoRender, otherwise CakePHP might still try to render your view and layout;
$this->autoRender = false;
Also, haven't tested it, but have you tried this to set the header:
// register the type
$this->response->type(array('docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'));
// set the type for the response
$this->response->type('docx');
See the documentation:
http://book.cakephp.org/2.0/en/controllers/request-response.html#dealing-with-content-types
You can modify the media.php file in the core of the framework and add the mime-type to the array that have the types.
Eg:
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
I have added in mime file:
'mp4' => array('video/mp4', 'video/3gpp'),
still not able to upload files. Not showing any errors also.
Any idea how to upload all types of files in codeigniter through form
Hi just add your mime type to
application/config/mimes
'mp4' =>'video/mp4'
'3gp'=>'video/3gpp'
then just add each one individually in the allowed types
Link for all the mime types
Make sure you are doing the right thing by checking the extension and the file type as well! For instance, if your file name is video.mp4, your file type is probably video/mp4 but not necessarily! (I was just dealing with a .m4a file and my audio type is audio/mp4.)
You can test the correct file type by printing it out for yourself after an upload.
echo $_FILES[0]['file_type'];
After that, you can add the following line to the mimes.php config file:
$mimes['<your extension>'] = '<your file type>';
Alternatively, if you encounter multiple MIME types for the same extension, you can add an array instead:
$mimes['<your extension>'] = array('<your file type 1>', '<your file type 2>');
I hope this helps!