Upload and save mp4 files in database in codeigniter - php

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!

Related

Check the uploaded file content is purely of that content type

If I put jpg header (1st line of a jpg file) in a HTML file and save it with jpg extension, then I can bypass the MIME type checking.
eg:
ÿØÿà JFIF d d ÿì Ducky < ÿî Adobe dÀ ÿÛ „
hyuhjjh
<script>
alert(hello);
</script>
If I save the above code as a JPG file then it can bypass the MIME type checking.
echo mime_content_type('x.html.jpg'); //shows 'image/jpeg'
I want the script to check the uploaded file content is purely of that content type( jpg/png or pdf or 3gp/mov). For image, document and video type.
OR doesn't contain any script.
Actually I need it for Drupal. So I have to use custom PHP code.
In Drupal 7.50 I have used "File Upload Secure Validator" to validate uploaded file MIME type, But it is useless for the above type of situation.
You need to use some library to actually load the file. For images I used GD to open the target image and check if it returns some reasonable height and width.
Same can be done with the other types. I guess that for video files this can be very resource-demanding, but it's the only way to be sure.

Codeigniter xml file not uploading

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

CodeIgniter's file upload library ignores allowed_types?

I tried to upload a certificate file and failed:
$config["allowed_types"] = "cer";
$this->load->library("upload", $config);
$this->upload->do_upload("fieldname");
I always get the following error, even if I upload a .cer file:
The filetype you are attempting to upload is not allowed
That is a lie, I uploaded a file of an allowed type!
Why does this class ignore its documented setting allowed_types?
You need to add the mime type in mimes.php config file. It should be something like this:
'cer' => array('application/x-x509-ca-cert', 'application/octet-stream'),
Location of mime: application/config/mime.php
I had a similar problem trying to upload csv's when they'd been generated by excel - in the end I had to use an extended list of mime types to allow the files to be uploaded. I've done a quick search for .cer mime-types and got two candidates, try using:
$config['allowed_types'] = 'cer|application/x-x509-ca-cert|application/pkix-cert';

CodeIgniter: wrong uploading file mime type

Sometimes, when uploading files using <input> tag, I encounter problem where the file extension doesn't match with its mime type defined in application/config/mimes.php. For example when I upload a .doc file, it turns out that its mime type is actually application/octet-stream, not application/msword as expected.
I had this problem sometimes in the past. I did work around by adding application/octet-stream to .doc mime array. But is there a proper way to fix it?
I think the browser have force my file's mime type somehow. Is there any kind of HTTP header or html meta tag to prevent this?
As you can see here this a common problem and the solution you applied is legitimate.
It is not due to problem with codeignitor. It is due to php issue. For instance finfo_file function will return image with extension jpeg as image/png.
So, solution is go to config/mimes.php file and then add corresponding extension.
In case you do not know what is the extension behind the scene php is picking add this code to check.
$finfo = #finfo_open(FILEINFO_MIME);
$mime = #finfo_file($finfo, $_FILES["myname"]['tmp_name']);
$mime will be extension which php finally returns.

Getting Upload Image mime type is application/octet-stream

While uploading file I am getting mime-type as application/octet-stream.
I have come to know that
Zend_Frameworks tries to determine the mimetype in two ways:
First it tries to use the PECL FILEINFO-Extension (which is not installed on every server)
if the extension is not istalled it tries to use mime_content_type (a php function). This function however is deprecated as of php version 5.3
So what to do now? How can I be sure that user uploading a file is image only and not something else? How can I detect mime type of uploaded file?
For images you can also rely on exif_imagetype but I would recommend that you install finfo.
See this for an example implementation.
Use Zend_File_Transfer validators to exlude types that you dont want :
$upload = new Zend_File_Transfer();
// Does not allow MIME type application/pdf and application/zip .
$upload->addValidator('ExcludeMimeType', false, array('application/pdf',
'application/zip'));
or you can also use IsImage validator which checks if a transferred file is a image file :
$upload = new Zend_File_Transfer();
// Checks whether the uploaded file is a image file
$upload->addValidator('IsImage', false);

Categories