Hey guys,
I'm having the most toughest time of my life to figure out a way to upload video files using PHP.
I am able to upload images but not video files or zip files. I haven't put any file extension check right now.
Here is my code, will you be able to find where i went wrong?
I am using CodeIgniter. Is there anything i need to do in CI to make this happen?
<form action="<?php echo current_url()?>" method="POST" enctype="multipart/form-data">
<input name="files[]" type="file" multiple required>
<input type="submit" name="form_submit" value="Upload Selected Items">
</form>
public function add(){
$data=$this->common();
$data['title']="Upload New Media";
$data['subtitle']="Upload Media & Add Info";
if(isset($_POST['form_submit'])){
var_dump($_FILES);
foreach($_FILES as $file){
for($i=0;$i<count($file)-1;$i++){
if(isset($file['name'][$i])){
/* for debugging */
echo $file['name'][$i]."<br>";
echo $file['type'][$i]."<br>";
echo $file['tmp_name'][$i]."<br>";
echo $file['error'][$i]."<br>";
echo $file['size'][$i]."<br><br>";
if($file['error'][$i]==0)
{
$tempFile = $file['tmp_name'][$i];
$fileName = $file['name'][$i];
$ext=explode(".",$fileName);
$targetPath = getcwd().'/uploads/'.$data['userid'].'/';
if(!file_exists($targetPath)) {mkdir($targetPath);}
$targetFile = $targetPath.substr(uniqid(rand()),0,90).'.'.end($ext);
if(move_uploaded_file($tempFile, $targetFile)==true){
echo "done!";
}
}
}
}
}
}
$this->load->view('admin/upload',$data);
}