Saturday, 15 January 2011

php - Upload image and video in codeigniter -



php - Upload image and video in codeigniter -

i seek upload video , image in codeigniter simultaneously image uploaded... html:

<form method="post" enctype="multipart/form-data" action="{$base_url}multimedia/save" > <b>image</b><br/> <input type="file" name="userfile" id="userfile"><br><br/> <b>video</b><br/> <input type="file" name="video" id="video"><br><br/> <input type="submit" value="save"></form>

my controller:

public function save() { $storage_image_path = 'path'; if ($_files["userfile"]["name"]) { move_uploaded_file($_files["userfile"]["tmp_name"], 'path' . $_files["userfile"]["name"]); $today_folders = date('y') .'/'. date('m'). '/' ; if ( !file_exists( $this->config->item("path") . 'big/' . $today_folders ) ){ $old_umask = umask(0); mkdir( $this->config->item("path") . 'large/' . $today_folders, 0777, true ); umask($old_umask); } $filename = $_files["userfile"]["name"]; $filename2 = $filename; $extension = end(explode(".", $filename)); $extcnt = strlen($extension) + 1; $fn_count = strlen($filename) - $extcnt; $replacename = substr($filename, 0, $fn_count); $newfilename = $replacename . date("-d"); $newfilename = $newfilename . '.' . $extension; $original_image = 'path' . $filename; $dimensions = getimagesize($original_image); $width = $dimensions[0]; $height = $dimensions[1]; if ($width >= $height) { $parametru = $width / 70; $height = round($height / $parametru); $width = 700; } else { $parametru = $height / 300; $width = round($width / $parametru); $height = 300; } $config['image_library'] = 'gd2'; $config['source_image'] = $original_image; $config['create_thumb'] = false; $config['maintain_ratio'] = true; $config['width'] = $width; $config['height'] = $height; $config['master_dim'] = 'width'; $config['new_image'] = $storage_image_path . '/big/' . $newfilename; $this->load->library('image_lib', $config); $this->image_lib->resize(); if (!$this->image_lib->resize()) { echo $this->image_lib->display_errors(); exit; } @unlink($original_image); } else { $newfilename = "no_photo.jpg"; $image = 0; } $this->db->query(" insert videos ( image, video) values (?, ?)", array( $image, 0) ); //$this->tpl->display('multimedia/add.php'); }

with function upload image, how modify method upload , video.please help me guys create lite this:

if ($_files["userfile1"]["name"]) { $filename_v = $_files["userfile1"]["name"]; $filenamev_2 = $filename; $config['upload_path'] = 'videos/mp4/'.$filename_v; $config['allowed_types'] = 'mov|mpeg|mp3|avi|mp4'; $this->load->library('upload', $config); if (!$this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); } else { $data = array('upload_data' => $this->upload->data()); } }

i don't errors video doesn't upload in specified path

by default upload routine expects file come form field called userfile, , form must "multipart type:

if set own field name pass value do_upload function:

$field_name = "some_field_name"; $this->upload->do_upload($field_name)

please read more @ http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

so in above scenario uploading video file next code should there.

$this->upload->do_upload('video');

php codeigniter codeigniter-2 codeigniter-url

No comments:

Post a Comment