First, this is the first time i code both of web service and android (normally just android), so please bear with me.
I tried to upload an image to the mysql (phpmyadmin) through the Codeigniter-based webservice. The image column in mysql (phpmyadmin) is BLOB.
$data['image'] = str_replace('data:image/jpg;base64,', '', $data['image']);
$data['image'] = str_replace(' ', '+', $data['image']);
$decoded= base64_decode($data['image']);
Then save the decoded file (this is where the permission is denied) :
file_put_contents('C:\xampp\htdocs\project\images', $decoded);
The image file should be saved in the "temp" folder, which is in the same folder with the php file (controller folder). However, the file is never stored (but the other data like name, email is stored on the mysql).
The error i got :
<p>Message: file_put_contents(C:\xampp\htdocs\project\images): failed to open stream: Permission denied</p>
Im kinda stuck now. Please kindly help me.
Thanks for your help
As per the error I think that the images directory must have the Read-Write Permission, so that images can be stored into it.
You can give 777 permission to the images folder. If you want to give then type the following code in the terminal
sudo chmod -R 777 path
Please take care you give permission to only images folder, and not the other folders
Related
I have a php site hosted in aws ec2 server.
While uploading files using php script it have only 0644(rw-r--r--) permissions in server. i need to change the file permissions to 0777(rwxrwxrwx).
What am doing is .. uploading a file and then read it and create a new encripted file using it and then delete the first file. its not happening because of file permission issue in aws uploading file through script.
uploaded files shows owner as 'apache' and transfer file using winSCP shows 'ec2-user'.
please help , am not much experinced in aws , so please please send your answers in detail.
Try This one.
Hope it will work
move_uploaded_file($temp_file, $UploadDirectory.$NewFileName );
chmod($UploadDirectory.$NewFileName, 0755);
$in_filename = $UploadDirectory.$NewFileName;
$aes_filename = //your path to new file with name;
$this->encryptFileCBC($in_filename, $aes_filename);
unlink($UploadDirectory.$NewFileName);
Code:
$filename = '12345.jpeg';
$source = imagecreatefromstring($imageData);
$imageSave = imagejpeg($source,$filename,100);
imagedestroy($source);
$this->ftp->connect();
$this->ftp->upload($imageSave,'/public_ftp/incoming/'.$filename,'ascii', 0775);
$this->ftp->close();
Error:
Codeigniter failed to open stream permission when upload images.
Probably it is a permissions issue. Try this:
sudo chmod -R 777 path/to/public_ftp/incoming/
However, this will give permission to everyone. For localhost this is ok. But for production environment you should do it in another way. Check this answer for more info
#edit
If you are getting this error when trying to upload a file from a form. codeigniter documentation:
The Upload Folder
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.
Do you have this folder with permissions set to 777?
I have ftp server which store my websites uploaded files. I am putting uploaded images into "upload" directory and then displaying on them to webpages with link to my photo editor tool.
Some how I can not access my ftp files in my photo editor. I figured that it is permission problem, but when I go to change permission for my upload directory files it fails to changes and says
"CHMOD 777 realtors.jpg: Operation not permitted."
let me know if any idea on how to solve this.
I'd like to upload file out of the *public_html* directory, because of security reasons, but I can't do this, because it gives me this error message:
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to access /opt/share/www/a/domainname/safety-download/file/20120517215405-2012-05-16--1-27-51.png in /opt/share/www/a/domainname/public_html/beta/admin/dokumentum.php on line 29
I don't want to use MySQL - BLOB file upload, because I don't have enough space in my MySQL server to upload over 3000 files, with more than 5 MB file size, but I'd like to deny the users from accessing these files, because they contain personal details.
Thanks for your answers,
Barnabas
Are you sure you have the rights to write in that folder ?
dirty fix
chmod a+w /opt/share/www/a/domainname/safety-download/file/
Or you can give the rights to apache to write in this folder. By changing the group of the folder to be the one of apache
And also make sure you call move_uploaded_file in the right order $src, $dest:
i'm working on a website wherein the users can upload images (uses php 4.3.11). the files are uploaded with no problem as i can see them in the upload directory and i don't get any error message, but when i try to access the uploaded files via ftp, i get an error: no such file or directory. sometimes, i am able to access the file sometimes i get this error. what could be the problem here?
[update]
thanks for the help guys. i'm not familiar with the ftp daemon stuff. but i do access my files via ftp using FireFTP. the files are there but when try to download them or change the file properties, i get the said error. i also tried uploading a file in the folder through ftp and i was able to download it with no problem.
here is some of the code i'm working on, its kind of roundabout but i'll see on how to improve it.
my working directory is something like this www.domain.com/register/
and the upload directory is here www.domain.com/register/uploads/
users are required to register and upon sign-up, a folder is created for them in the uploads directory. i couldn't find a way to create a folder without having to be in the uploads folder itself so i redirect to a create-user-folder.php file in the uploads dir.
the file just contained this code:
$user_foldername = rawurldecode($_GET['name']);
mkdir($user_foldername);
header("Location: ../form.php"); // redirect back to the page
i checked and the created folder's permission is set to 775.
and here's part of the code i use in uploading ( /register/function/function.php ):
$path = "../uploads/$user_foldername/";
for($j = 0; $j < $num_of_uploads; $j++){
if(is_uploaded_file($_FILES[$file]['tmp_name'][$j])){
$filename = $_FILES[$file]['name'][$j];
copy($_FILES[$file]['tmp_name'][$j],$path.$filename);
}
}
i checked using FireFTP and the files are in the /uploads/user_foldername/ directory and its permission is set to 664. the strange thing is that when i try to download the files, at times there would be no problem at all but there are times when the error will appear.
[another update]
i added chmod() after the copy() function,
$filename = $_FILES[$file]['name'][$j];
copy($_FILES[$file]['tmp_name'][$j],$path.$filename);
chmod($path.$filename, 0755);
but i still get the error.
another thing is that when i access /register/uploads/user_foldername/ through the url, i can see all of the uploaded files and view them, but how is it that i can't access them via ftp?
thanks again!
This is either a permission issue, or a configuration error. Here are things you should try:
What are the permission of the uploaded files? Does the FTP user has access to these files? Have you tried logging in as the user the FTP daemon would use and see if you could read the file that way?
Do you really see the correct directory? Have you verified by putting a file in that directory yourself and downloading it? Have you used the ftp command ls to verify the presence of the folder/folders/files?
You might need to chmod the folder the files are in, or in some cases the files themselves.
try chmoding them to 775
You can chmod files and folders through PHP it's self, with the chmod function. Or, you could use a FTP program such as filezilla.
Also check to make sure the intermediate directories are also permissioned as 755, as all the directories in the path need to be executable to be traversed.
i just figured out the problem. it was all because of the file name having accented characters in it, which explains why i do not always get the error message :|
<sigh> i should have seen this earlier, but anyway i hope this helps in case someone ran into the same problem.
thanks again! i really appreciate it :)