Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

php - Upload path on Codeigniter returns "the upload path doesn't seem to be valid"

Now i've tried most of the fixes that i've read, most of them mention about APPPATH, base_url(), real path and etc. but i really don't know why all of them didn't work, what worked for me is that i've used the actual path, not a url but the one with the C:xampphtdocs.. blah blah blah.. now i've read one thread that url and directory aren't the same thing.. and the upload_path accepts only directory path and i mean the actual location of the uploads folder on the server not the URL.. now my question is how come APPPATH don't work. as what i know it the actual directory path. but when i tried to display is it return only "../applicaiton/" what really is the best path to be used on the $config['upload_path'] on the upload.php specially when deploying it to an actual server it is really a nuisance finding the directory path of your upload folder, NOTE im not using the initialize() method i'm putting my configs on config/upload.php

EDITS:

i have this on a separate file... upload.php

<?php 
$config['upload_path'] ='./uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '5000';
$config['max_width'] = '1600';
$config['max_height'] = '1200';

and this is my controller

     if($this->upload->do_upload('image'))
     {
         //Did something here
     }
     else
     {
        //Did something for errors like display_errors()
     }

and end result is it displays "the upload path doesn't seem to be valid" and i've tried these line of code also

Trial 1:

$config['upload_path'] ='./uploads/';

Trial 2:

$config['upload_path'] ='uploads/';

Trial 3:

$config['upload_path'] ='/admin/assets/uploads/';

Trial 4:

$config['upload_path'] ='./admin/assets/uploads/';

Trial 5:

$config['upload_path'] ='admin/assets/uploads/';

the only thing that works is this

 $config['upload_path'] ='C:xampphtdocspracticeadmin.abcgenconadminassetsuploads'';

and using the last part as a path is kinda messy so i've tried also APPPATHbut it doesn't work also it also display "../application"..

as @cryptic said i've posted this code snippet.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Question, you tried realpath and APPPATH seperately?

In Codeigniter APPPATH points to the application folder.

Example: (place your folder outside the application folder, just saying if you did not do that way) let's say the folder where we want to place the files called images.

So what you need to do is to combine realpath() and APPPATH

$image_path = realpath(APPPATH . '../images');

and pass it to your config

$config['upload_path'] = $image_path;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...