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

[eluser]learning_php[/eluser]
Hi,

I am trying to get a file upload working but it keeps telling me that the file path is not valid. I a have folder called upload with full permissions so i am a little stuck.

Code:
function upload(){
            //$cong setting
            $config['upload_path'] = './wedding-site/assets/upload';
            $config['allowed_types']='png|jpg|gif';
            $config['max_size']= '20000';
            
            //upload file
            $this->load->library('upload',$config);
            
            if($this->upload->do_upload()){
                
                $data['upload_data'] = $this->upload->data();
            }
            else{
                $data['error'] = $this->upload->display_errors();
            }
            $this->load->view('upload',$data);
        }
#2

[eluser]Dam1an[/eluser]
I think you need the forward slash on the end of your upload path
#3

[eluser]learning_php[/eluser]
I changed it to this but i get the same error:
Code:
$config['upload_path'] = './wedding-site/assets/upload/';
#4

[eluser]Dam1an[/eluser]
Oh Sad
I just saw the page in the user guide had a forward slash and you didn't so assumed that was it

Is the invalid path a PHP error, or one produced by CI (when you reload the upload view)
#5

[eluser]learning_php[/eluser]
It happens with I load the upload.php view page which only contains the code to either print the error or redirect to another page.

Code:
<?PHP
if(isset($error)){
    echo $error;
}else{
    redirect('images');
}

?>
#6

[eluser]Dam1an[/eluser]
Try using the file helper to write a file (some random text) to you upload directory, see if that works...
That might give a clue as to where the problem lies
#7

[eluser]learning_php[/eluser]
Hi,

i added to the upload view:
Code:
<?PHP
if(isset($error)){
    echo $error;
}else{
    redirect('images');
}
$data = 'Some file data';

if ( ! write_file('./wedding-site/assets/upload/', $data))
{
     echo 'Unable to write the file';
}
else
{
     echo 'File written!';
}


?>

and now it displays The upload path does not appear to be valid.
Unable to write the file
#8

[eluser]Dam1an[/eluser]
Have you tried giving it an absolute file system path, instead of one relative to index.php
#9

[eluser]learning_php[/eluser]
Hi,

When i give use this it writes the file?

Code:
$data = 'Some file data';

if ( ! write_file('C:/xampp/htdocs/wedding-site/assets/upload/file.txt', $data))
{
     echo 'Unable to write the file';
}
else
{
     echo 'File written!';
}
#10

[eluser]learning_php[/eluser]
Hi,

I have been reading the forum post and it seems other people have had the same error and it seems that changign the line to this works
Code:
$config['upload_path'] = './assets/upload';
but I seem to still get the the same error.




Theme © iAndrew 2016 - Forum software by © MyBB