Hello Everyone!

I am unable to upload fiels using Code Igniter framework.
I have one form with the help of it need to upload 4 images in fabrics folder each time.
Before uploading images I need to create folder sructure also but unable to do so by giving absolute path like
mkdir(ADMIN_DATA."uploaded/shirt/parts/".$fabric_type, 0777).
Was able to create folder with the path like
mkdir("C:/xampp/htdocs/project/admin_data/uploaded/shirt/parts/".$fabric_type, 0777)
Also images was going correctly while adding on local system.

I want to do it on test server instead on local system so I did changes of mkdir(ADMIN_DATA."uploaded/shirt/parts/".$fabric_type, 0777) which made me unable to make folders ,also unable to upload images .

$config['upload_path'] = ADMIN_DATA.'uploaded/shirt/fabrics/';
        $config['allowed_types'] = 'gif|jpg|png';

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


        if (!$this->upload->do_upload('short_image'))   
        { 
             // echo "warning";
            $_FILES['short_image']['type']='application/png';
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('admin/pdflist', $error);

        }
        else
        {  
            $data1 = array('upload_data' => $this->upload->data());
            print_r($data);

        }

After uploading images it gives below error:

An Error Was Encountered

Unable to load the requested file: admin/pdflist.php

Any help would be appreciated!

Thanks.

Dani AI

Generated

is on the right track: upload_path must be a filesystem path that exists and is writable by PHP. On Windows your absolute C:... path worked, but on Linux a custom constant like ADMIN_DATA needs to resolve to a real server path too. A portable pattern is to build paths off FCPATH (the folder with index.php) and create missing folders before uploading.

// application/config/constants.php
define('ADMIN_DATA', FCPATH.'admin_data/');

// In your controller, before uploading
$dir = ADMIN_DATA.'uploaded/shirt/parts/'.$fabric_type.'/';
if (!is_dir($dir) && !mkdir($dir, 0775, true)) {
    show_error('Failed to create: '.$dir);
}
$this->load->library('upload', [
    'upload_path'   => $dir,
    'allowed_types' => 'gif|jpg|jpeg|png',
]);

Tips that usually solve this class of issues:

  • Ensure your form has enctype="multipart/form-data".
  • Prefer 0755/0775 with correct ownership (www-data/apache) over 0777. Use is_really_writable($dir) to verify.
  • Do not change $_FILES[...]['type']; let CI validate the file. Also watch case-sensitive extensions on Linux.
  • For 4 images, call do_upload() once per field name in a loop (each input must have its own name).

For : the message "Unable to load the requested file: admin/pdflist.php" is not an upload failure; it means the view loader could not find the file at application/views/admin/pdflist.php. Either create that view at exactly that path (case-sensitive on Linux) or change the call to match the real location/name, e.g. $this->load->view('admin/pdf_list'). Once the view is found, you will see the real upload errors (if any) returned by $this->upload->display_errors().

Solved after trying some hours finally!
Instead of giving below address
$config = ADMIN_DATA.'uploaded/shirt/fabrics/';
I gave full path ommited config variable ADMIN_DATA and also changed folder permision
with chmod('folderfullpath',0777);

how you do that can you give this information to me plz

I want to upload picture by codeigniter but it give and error like unable to load the requested file how can I fix that plz help me!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.