public functions shows error in dreamweaver ?
"there syntax error on line 108, code hitting maynot work untill u fix error" here public functions shows error in dreamweaver weel net beans, paste code in ur dreamweaver
<?php if (!defined('basepath'))
exit('no direct script access allowed');
class upload extends ci_controller {
protected $path_img_upload_folder;
protected $path_img_thumb_upload_folder;
protected $path_url_img_upload_folder;
protected $path_url_img_thumb_upload_folder;
protected $delete_img_url;
function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
//set relative path ci constant
$this->setpath_img_upload_folder("assets/img/articles/");
$this->setpath_img_thumb_upload_folder("assets/img/articles/thumbnails/");
//delete img url
$this->setdelete_img_url(base_url() . 'admin/deleteimage/');
//set url img base_url()
$this->setpath_url_img_upload_folder(base_url() . "assets/img/articles/");
$this->setpath_url_img_thumb_upload_folder(base_url() . "assets/img/articles/thumbnails/");
}
public function index() {
$this->load->view('upload_v/upload_view');
}
// function called form
public function upload_img() {
//format name
$name = $_files['userfile']['name'];
$name = strtr($name, 'àÁÂÃÄåÇèÉÊëìÍîÏòóÔÕöùúûüýàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'aaaaaaceeeeiiiiooooouuuuyaaaaaaceeeeiiiioooooouuuuyy');
// replace characters other letters, numbers , . _
$name = preg_replace('/([^.a-z0-9]+)/i', '_', $name);
//your upload directory, see ci user guide
$config['upload_path'] = $this->getpath_img_upload_folder();
$config['allowed_types'] = 'gif|jpg|png|jpg|gif|png';
$config['max_size'] = '1000';
$config['file_name'] = $name;
//load upload library
$this->load->library('upload', $config);
if ($this->do_upload()) {
//if want resize
$config['new_image'] = $this->getpath_img_thumb_upload_folder();
$config['image_library'] = 'gd2';
$config['source_image'] = $this->getpath_img_upload_folder() . $name;
$config['create_thumb'] = false;
$config['maintain_ratio'] = true;
$config['width'] = 193;
$config['height'] = 94;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$data = $this->upload->data();
//get info
$info = new stdclass();
$info->name = $name;
$info->size = $data['file_size'];
$info->type = $data['file_type'];
$info->url = $this->getpath_img_upload_folder() . $name;
$info->thumbnail_url = $this->getpath_img_thumb_upload_folder() . $name; //i set original file since did not create thumbs. change thumbnail directory if = $upload_path_url .'/thumbs' .$name
$info->delete_url = $this->getdelete_img_url() . $name;
$info->delete_type = 'delete';
//return json data
if (is_ajax) { //this why put in constants pass json data
echo json_encode(array($info));
//this has only data returned or error.
//if don't give json array give empty file upload result error
//it set without if(is_ajax)...else... error:true (my experience anyway)
} else { // still work if javascript not enabled
$file_data['upload_data'] = $this->upload->data();
echo json_encode(array($info));
}
} else {
// display_errors() function wraps error messages in <p> default , these html chars don't parse in
// default view on forum either set them blank, or decide how want them display. null passed.
$error = array('error' => $this->upload->display_errors('',''));
echo json_encode(array($error));
}
}
}
//function upload : return true/false
public function do_upload() {
if (!$this->upload->do_upload()) {
return false;
} else {
//$data = array('upload_data' => $this->upload->data());
return true;
}
}
//function delete image
public function deleteimage() {
//get name in url
$file = $this->uri->segment(3);
$success = unlink($this->getpath_img_upload_folder() . $file);
$success_th = unlink($this->getpath_img_thumb_upload_folder() . $file);
//info see if doing supposed to
$info = new stdclass();
$info->sucess = $success;
$info->path = $this->getpath_url_img_upload_folder() . $file;
$info->file = is_file($this->getpath_img_upload_folder() . $file);
if (is_ajax) {//i don't think matters if set error checking in console/firebug
echo json_encode(array($info));
} else { //here need decide want show successful delete
var_dump($file);
}
}
//load files
public function get_files() {
$this->get_scan_files();
}
//get info , scan directory
public function get_scan_files() {
$file_name = isset($_request['file']) ?
basename(stripslashes($_request['file'])) : null;
if ($file_name) {
$info = $this->get_file_object($file_name);
} else {
$info = $this->get_file_objects();
}
header('content-type: application/json');
echo json_encode($info);
}
protected function get_file_object($file_name) {
$file_path = $this->getpath_img_upload_folder() . $file_name;
if (is_file($file_path) && $file_name[0] !== '.') {
$file = new stdclass();
$file->name = $file_name;
$file->size = filesize($file_path);
$file->url = $this->getpath_url_img_upload_folder() . rawurlencode($file->name);
$file->thumbnail_url = $this->getpath_url_img_thumb_upload_folder() . rawurlencode($file->name);
//file name in url delete
$file->delete_url = $this->getdelete_img_url() . rawurlencode($file->name);
$file->delete_type = 'delete';
return $file;
}
return null;
}
//scan
protected function get_file_objects() {
return array_values(array_filter(array_map(
array($this, 'get_file_object'), scandir($this->getpath_img_upload_folder())
)));
}
// getter & setter
public function getpath_img_upload_folder() {
return $this->path_img_upload_folder;
}
public function setpath_img_upload_folder($path_img_upload_folder) {
$this->path_img_upload_folder = $path_img_upload_folder;
}
public function getpath_img_thumb_upload_folder() {
return $this->path_img_thumb_upload_folder;
}
public function setpath_img_thumb_upload_folder($path_img_thumb_upload_folder) {
$this->path_img_thumb_upload_folder = $path_img_thumb_upload_folder;
}
public function getpath_url_img_upload_folder() {
return $this->path_url_img_upload_folder;
}
public function setpath_url_img_upload_folder($path_url_img_upload_folder) {
$this->path_url_img_upload_folder = $path_url_img_upload_folder;
}
public function getpath_url_img_thumb_upload_folder() {
return $this->path_url_img_thumb_upload_folder;
}
public function setpath_url_img_thumb_upload_folder($path_url_img_thumb_upload_folder) {
$this->path_url_img_thumb_upload_folder = $path_url_img_thumb_upload_folder;
}
public function getdelete_img_url() {
return $this->delete_img_url;
}
public function setdelete_img_url($delete_img_url) {
$this->delete_img_url = $delete_img_url;
}
}
More discussions in Web Developer Discussion
adobe
Comments
Post a Comment