Welcome Guest, Not a member yet? Register   Sign In
upload
#1

CodeIgniter File Upload Demo

Select File to Upload
 
The upload path does not appear to be valid.

------------------------------------

I already try to upload any image and "The upload path does not appear to be valid."



views/upload_file_view.php

PHP Code:
<div class="container">
 
   <div class="row">
 
       <div class="col-md-6 col-md-offset-3 well">
 
       <legend>CodeIgniter File Upload Demo</legend>
 
       <?php echo form_open_multipart('uploadfile/upload');?>

        <fieldset>
            <div class="form-group">
                <div class="row">
                    <div class="col-md-12">
                        <label for="filename" class="control-label">Select File to Upload</label>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="row">
                    <div class="col-md-12">
                        <input type="file" name="filename" size="20" />
                        <span class="text-danger"><?php if (isset($error)) { echo $error; } ?></span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="row">
                    <div class="col-md-12">
                        <input type="submit" value="Upload File" class="btn btn-primary"/>
                    </div>
                </div>
            </div>
        </fieldset>
        
        <?php echo form_close(); ?>
        <?php if (isset($success_msg)) { echo $success_msg; } ?>
        </div>
    </div>
</div> 


controllers/uploadfile.php

PHP Code:
<?php



class uploadfile extends CI_Controller {

 
   function __construct()
 
   {
 
       parent::__construct();
 
       $this->load->helper(array('form''url'));
 
   }

 
   //index function
 
   function index()
 
   {
 
       //load file upload form
 
       $this->load->view('upload_file_view');
 
   }

 
   //file upload function
 
   function upload()
 
   {
 
       //set preferences
 
       $config['upload_path'] = 'uploads/';
 
       $config['allowed_types'] = 'txt|pdf';
 
       $config['max_size'   '100';

 
       //load upload class library
 
       $this->load->library('upload'$config);

 
       if (!$this->upload->do_upload('filename'))
 
       {
 
           // case - failure
 
           $upload_error = array('error' => $this->upload->display_errors());
 
           $this->load->view('upload_file_view'$upload_error);
 
       }
 
       else
        
{
 
           // case - success
 
           $upload_data $this->upload->data();
 
           $data['success_msg'] = '<div class="alert alert-success text-center">Your file <strong>' $upload_data['file_name'] . '</strong> was successfully uploaded!</div>';
 
           $this->load->view('upload_file_view'$data);
 
       }
 
   }
}


?>
" If I looks more intelligence please increase my reputation."
Reply
#2

(05-16-2016, 04:34 PM)davy_yg Wrote: CodeIgniter File Upload Demo

Select File to Upload
 
The upload path does not appear to be valid.

------------------------------------

I already try to upload any image and "The upload path does not appear to be valid."



views/upload_file_view.php

PHP Code:
<div class="container">
 
   <div class="row">
 
       <div class="col-md-6 col-md-offset-3 well">
 
       <legend>CodeIgniter File Upload Demo</legend>
 
       <?php echo form_open_multipart('uploadfile/upload');?>

        <fieldset>
            <div class="form-group">
                <div class="row">
                    <div class="col-md-12">
                        <label for="filename" class="control-label">Select File to Upload</label>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="row">
                    <div class="col-md-12">
                        <input type="file" name="filename" size="20" />
                        <span class="text-danger"><?php if (isset($error)) { echo $error; } ?></span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="row">
                    <div class="col-md-12">
                        <input type="submit" value="Upload File" class="btn btn-primary"/>
                    </div>
                </div>
            </div>
        </fieldset>
        
        <?php echo form_close(); ?>
        <?php if (isset($success_msg)) { echo $success_msg; } ?>
        </div>
    </div>
</div> 


controllers/uploadfile.php

PHP Code:
<?php



class uploadfile extends CI_Controller {

 
   function __construct()
 
   {
 
       parent::__construct();
 
       $this->load->helper(array('form''url'));
 
   }

 
   //index function
 
   function index()
 
   {
 
       //load file upload form
 
       $this->load->view('upload_file_view');
 
   }

 
   //file upload function
 
   function upload()
 
   {
 
       //set preferences
 
       $config['upload_path'] = 'uploads/';
 
       $config['allowed_types'] = 'txt|pdf';
 
       $config['max_size'   '100';

 
       //load upload class library
 
       $this->load->library('upload'$config);

 
       if (!$this->upload->do_upload('filename'))
 
       {
 
           // case - failure
 
           $upload_error = array('error' => $this->upload->display_errors());
 
           $this->load->view('upload_file_view'$upload_error);
 
       }
 
       else
        
{
 
           // case - success
 
           $upload_data $this->upload->data();
 
           $data['success_msg'] = '<div class="alert alert-success text-center">Your file <strong>' $upload_data['file_name'] . '</strong> was successfully uploaded!</div>';
 
           $this->load->view('upload_file_view'$data);
 
       }
 
   }
}


?>
Reply
#3

(05-16-2016, 04:34 PM)davy_yg Wrote: I am pretty sure you make uploads directory inside view folder. Simply move it out to the root directory.


CodeIgniter File Upload Demo

Select File to Upload
 
The upload path does not appear to be valid.

------------------------------------

I already try to upload any image and "The upload path does not appear to be valid."



views/upload_file_view.php

PHP Code:
<div class="container">
 
   <div class="row">
 
       <div class="col-md-6 col-md-offset-3 well">
 
       <legend>CodeIgniter File Upload Demo</legend>
 
       <?php echo form_open_multipart('uploadfile/upload');?>

        <fieldset>
            <div class="form-group">
                <div class="row">
                    <div class="col-md-12">
                        <label for="filename" class="control-label">Select File to Upload</label>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="row">
                    <div class="col-md-12">
                        <input type="file" name="filename" size="20" />
                        <span class="text-danger"><?php if (isset($error)) { echo $error; } ?></span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="row">
                    <div class="col-md-12">
                        <input type="submit" value="Upload File" class="btn btn-primary"/>
                    </div>
                </div>
            </div>
        </fieldset>
        
        <?php echo form_close(); ?>
        <?php if (isset($success_msg)) { echo $success_msg; } ?>
        </div>
    </div>
</div> 


controllers/uploadfile.php

PHP Code:
<?php



class uploadfile extends CI_Controller {

 
   function __construct()
 
   {
 
       parent::__construct();
 
       $this->load->helper(array('form''url'));
 
   }

 
   //index function
 
   function index()
 
   {
 
       //load file upload form
 
       $this->load->view('upload_file_view');
 
   }

 
   //file upload function
 
   function upload()
 
   {
 
       //set preferences
 
       $config['upload_path'] = 'uploads/';
 
       $config['allowed_types'] = 'txt|pdf';
 
       $config['max_size'   '100';

 
       //load upload class library
 
       $this->load->library('upload'$config);

 
       if (!$this->upload->do_upload('filename'))
 
       {
 
           // case - failure
 
           $upload_error = array('error' => $this->upload->display_errors());
 
           $this->load->view('upload_file_view'$upload_error);
 
       }
 
       else
        
{
 
           // case - success
 
           $upload_data $this->upload->data();
 
           $data['success_msg'] = '<div class="alert alert-success text-center">Your file <strong>' $upload_data['file_name'] . '</strong> was successfully uploaded!</div>';
 
           $this->load->view('upload_file_view'$data);
 
       }
 
   }
}


?>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB