Reputation: 41
I'm trying to upload a video.
My mime config:
'wmv' => array('video/wmv', 'video/x-ms-wmv', 'flv-application/octet-stream', 'application/octet-stream'),
'flv' => array('video/x-flv', 'flv-application/octet-stream', 'application/octet-stream'),
'mp4' => 'video/mp4',
'3gp' => 'video/3gpp'
My view:
<div id="upload">
<?php
echo form_open_multipart('audio');
echo form_upload('userfile');
echo form_submit('upload','Upload');
echo form_close();
?>
</div>
My controller:
function index() {
$this->load->model('Audio_model');
if ($this->input->post('upload')) {
$this->Audio_model->do_upload();
}
$this->load->view('v_audio');
}
My model:
function do_upload() {
$config = array(
'allowed_types' => 'mp4|3gp|flv|mp3',
'max_size'=>'100000',
'upload_path' => $this->gallery_path
);
$this->load->library('upload', $config);
if ($this->upload->do_upload()) {
echo "Upload success!";
} else {
echo "Upload failed!";
}
}
I can upload mp3's successfully, but not mp4, 3gp or flv, they all fail to upload.
Upvotes: 4
Views: 12150
Reputation: 11
$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma");
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
if ((($_FILES["file"]["type"] == "video/mp4")
|| ($_FILES["file"]["type"] == "audio/mp3")
|| ($_FILES["file"]["type"] == "audio/wma")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"video/" . $_FILES["file"]["name"]);
echo "Stored in: " . "video/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
Upvotes: 0
Reputation: 139
Add mime type in the config/mimes.php
'flv' => array('video/x-flv', 'flv-application/octet-stream', 'application/octet-stream'),
'mp4' => 'video/mp4',
'3gp' => 'video/3gpp'
and in root folder make Video folder its enough.....
Upvotes: 2
Reputation: 41
Check with upload path and pass the name of the to $this->upload->do_upload('userfile') and increase max_size(upload_max_filesize = 10M) in php.ini
Upvotes: 0