The upload path does not appear to be valid. - ahsan - 12-14-2016
Hi,
I am trying to upload a file on live server cPanel but it not uploading and i am getting the error
Code: The upload path does not appear to be valid.
and some time 500-internal server error
But the thing is same code is running on my local machine wamp and every thing is perfect. I give full permissions to the upload folder and upload folder is on root where index.php is there
Controller:
PHP Code: <?php defined('BASEPATH') OR exit('No direct script access allowed');
class Careers extends CI_Controller { function __construct(){ parent::__construct(); $this->load->library(array('upload','session','javascript','encrypt','email','form_validation')); $this->load->helper(array('form','text','html','url','email','lang','file','directory')); $this->load->driver(array('session')); $this->load->model('Careers_model','model'); } public function index($lang=false) { $vars['lang'] =langhomename($lang); $langid=langhomeid($lang); $this->load->view('careers/index',$vars); } public function cvcareers($lang=false){ $vars['lang'] =langhomename($lang); $langid=langhomeid($lang); $this->model->cvcareers($vars); } }
Model:
PHP Code: <?php class Careers_model extends CI_Model {
public function __construct(){ $this->load->database(); } public function cvcareers($vars){ //getting values from the submitted form $designation = $_POST['career-designation']; $email = $_POST['career-email']; $name = $_POST['career-name']; $number = $_POST['career-number']; $msg = $_POST['career-msg']; $cvdata = ''; //Uploading file to the directory $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = 1000;
$this->load->library('upload', $config); if (!$this->upload->do_upload('userfile')) { $vars['cv_status']= array('error' => $this->upload->display_errors()); print_r($vars); echo 'Uploaderror'; } else { $cvdata= $this->upload->data(); //assiging form data in array to pass to the database function $data = array( 'designation' => $designation, 'email' =>$email, 'name'=>$name, 'number'=>$number, 'message'=>$msg, 'path'=>$config['upload_path'], //'cv' =>$cvdata['file_name'], 'cv' =>'filename', ); //Inserting data into the database $this->db->insert('careers', $data); //Genrating email for sending, $mailconfig['protocol'] = 'smtp'; $mailconfig['smtp_host'] = 'ssl://smtp.gmail.com'; //change this $mailconfig['smtp_port'] = '465'; $mailconfig['smtp_user'] = '@gmail.com'; //change this $mailconfig['smtp_pass'] = ''; //change this $mailconfig['mailtype'] = 'html'; $mailconfig['charset'] = 'iso-8859-1'; $mailconfig['wordwrap'] = TRUE; $mailconfig['newline'] = "\r\n"; $this->load->library('email',$mailconfig); $subject="CV"; //Genrating email template by entered user data $message =message($designation,$email,$name,$number,$msg,$cvdata); //attaching file with the email $this->email->attach($cvdata["full_path"]); $this->email->set_newline("\r\n"); $this->email->set_mailtype("html"); $this->email->from('@gmail.com'); $this->email->to('@gmail.com'); $this->email->subject($subject); $this->email->message($message);
if($this->email->send()) { echo 'Emailsent'; } else { //show_error($this->email->print_debugger()); $emailerror=$this->email->print_debugger(); } }
}
}
.htaccess
PHP Code: RewriteEngine on Options -Indexes RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$1 [L] RewriteCond %{HTTP_HOST} ^sitename\.com$ [NC] RewriteRule ^(.*)$ http://www.sitename.com/$1 [R=301,L] Header add Access-Control-Allow-Origin "*" Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type" Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
RE: The upload path does not appear to be valid. - BabalooAye - 12-15-2016
Is your host a Linux server?
RE: The upload path does not appear to be valid. - ahsan - 12-18-2016
(12-15-2016, 06:55 AM)BabalooAye Wrote: Is your host a Linux server?
Yes its on linux machine, Thanks for replying but my problem is resolved there is no issue in the code the issue was Fileinfo module was not enabled.
RE: The upload path does not appear to be valid. - wolfgang1983 - 12-18-2016
Why did you put it in model?
Try controller instead and then send success data to model
https://www.codeigniter.com/user_guide/libraries/file_uploading.html#the-controller
RE: The upload path does not appear to be valid. - universalbits - 06-18-2017
Load upload file library same official doc:
Controller
Code: <?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Careers extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
$this->load->library(array('session','javascript','encrypt','email','form_validation'));
$this->load->helper(array('text','html','email','lang','file','directory'));
$this->load->driver(array('session'));
$this->load->model('Careers_model','model');
public function index($lang=false)
{
$vars['lang'] =langhomename($lang);
$langid=langhomeid($lang);
$this->load->view('careers/index',$vars);
}
public function cvcareers($lang=false){
$vars['lang'] =langhomename($lang);
$langid=langhomeid($lang);
$this->model->cvcareers($vars);
}
}
The important thing to specify the directory and set chmod permissions.
|