Reputation: 3267
This is my uploadinfg files code in codeigniter application
function upload_logo(){
$ex=$_FILES['uploadfile']['name'];
$epld=explode('.',$ex);
$filename=date("mdyHis").".".$epld[1];
$userfile_size=$_FILES['uploadfile']['size'];
$imggtype=$_FILES['uploadfile']['type'];
if(move_uploaded_file($_FILES['uploadfile']['tmp_name'],"./uploads/".$filename))
{
echo $filename;
}
}
Here uploadfile
is the name of the file field.And i have a folder with name uploads in root folder.When i uploading file i got errors.This is working in our server but not working in client's server.
A PHP Error was encountered
Severity: Warning
Message: move_uploaded_file(./uploads/112911224341.docx) [function.move-uploaded-file]: failed to open stream: Permission denied
Filename: controllers/pms.php
Line Number: 156
A PHP Error was encountered
Severity: Warning
Message: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpvhzCkw' to './uploads/112911224341.docx'
Filename: controllers/pms.php
Line Number: 156
How can i solve this?
Upvotes: 3
Views: 11123
Reputation: 10548
If UBUNTU OS, Then Go to that folder where you are uploading/keeping 'Uploaded Files', Right Click To That Folder ->Properties -> Permissions Then, Change All 'Access' to create and delete files.
If also, not happening, then go to its parent folder, and follow the same step. I'm sure, you will not get this issue. Because, just now, i got this error. and, i solved like this way only.
Upvotes: 0
Reputation: 2676
This error happens due to two reasons.
If you are in Linux. Open terminal type this command. This will change the owner of the folder.
$ cd project_path && sudo chown -R www-data:www-data picture_folder/
Type this command to change the permission of folder.
$ sudo chmod -R 777 picture_folder/
note : Use man command more help about these commands.
$ man chmod OR man chown
In codeigniter, index.php root file is executed. That is responsible for all activities. So don't use base_url() for root path. Instead. Just give root folder name. like
CI application ->
-application
-system
-user_guide
-index.php
-picture_folder
$target_directory="picture_folder/sub_folder";
Upvotes: 0
Reputation: 21575
The error message states that it's a permissions issue. Ensure that you have the correct permissions set on the the uploads folder. From the documentation:
You'll need a destination folder for your uploaded images. Create a folder at the root of your CodeIgniter installation called uploads and set its file permissions to 777.
Upvotes: 1