Permissions to files after upload with php - php

I having a problem which when files are uploaded to there folder with PHP they don't have any permissions to then view them on my website.
I'm using IIS and the IIS permission doesn't get set when the folder has the correct permissions.
Because what I'm doing it uploading the file location to my database then using that to display it on page if i change the file permissions it works fine but i would have to do this every time something is uploaded to my server.
Thanks,

Related

WAMP restrict file upload for executable file

I am using wamp server .
I wrote a code where user could upload file and the uploaded file will be stored in the server for further processing .
I wanted to restrict the executable file upload to this API
so that only .feature files can be uploaded.
is there any way in WAMP server that we could restrict such file uploads
You could restrict your file types with your script. Don't need to do things on WAMP.
Please see the below link for more info. It is explaining how to do it

php ftp_get local user

I'm downloading files from a remote ftp location using php ftp_get() function. Downloading and saving the file is done perfectly, but the file is saved on the local server with different user rights.
Looking at the files, all files uploaded by FTP get the user of the site profile. But files downloaded by a script (executed through a browser) get the user apache.
So at a later stage, a cronjob, who is a different user (site user) can't access these files. Because it has no permission.
So how could u I save the file using ftp_get() with the correct user and group?
Maybe change file permissions using
http://php.net/manual/en/function.chown.php
and
http://php.net/manual/en/function.chmod.php

Ftp craeting folder and setting permission with php

I am making uploading site that creates folder for each user to store his pics in , i tried to make the folder with the php normal function mkdir and setting the permissions to 0777 it's creating the folder but i cant add files from the php program only copying through windows explorer in the ftp server , but if i made the folder through ftp server and set the permissions manually it worked and uploaded pics , so i tried the ftp_mkdir with the following code :
$uploaddir="httpdocs/pics/".$uid.$uname;
if(!is_dir ($uploaddir))
{
ftp_mkdir($conn, $uploaddir);
ftp_chmod($conn,"0777", $uploaddir);
}
ftp_close($conn);
it's creating the folder but not with full permissions so you cant upload files to the folder until you set the permissions manually then it works fine

Upload path on Codeigniter gives error in Openshift

I am trying to upload image to my Codeigniter application hosted on Openshift. My app structure is as follows
App
-libs
-...
-php
- application
- public
- uploads
I want to upload images to this uploads folder. my code
$config['upload_path']=realpath(dirname(__FILE__)).'public/uploads/';
$config['allowed_types']="jpg|jpeg|gif|png";
$this->load->library('upload',$config);
if(!($this->upload->do_upload())){
$error=array('error'=>$this->upload->display_errors());
$this->load->view('profile',$error);
}
else{
$file_data=$this->upload->data();
$data['img']=base_url().'/public/uploads/'.$file_data['file_name'];
$this->load->view('success',$data);
}
But above gives me The upload path does not appear to be valid. error. I have tried several ways. But the problem is the server do not allow to upload to the location.
Normally I can access the files in the uploads folder. But when I try to write data (store file) it doesn't allow. How can I fix this thing.
Note: I want the solution for the Openshift server but not the localhost
The path is supposed to be $OPENSHIFT_DATA_DIR (which points to ~/app_root/data).
You can also write to /tmp but those files will be treated as ephemeral.
You do not have write permissions anywhere in the file system.

Odd permissions on file modified by PHP move_uploaded_file()

I'm running PHP 5.2.6 on a Windows Server 2003 Enterprise box. IIS is set to deny anonymous access and use Integrated Windows authentication.
I'm using a PHP script to save a file uploaded from a web form. The file is uploaded to a temp folder, the script creates a file name and path depending on other variables from the web form, and then the script uses PHP's move_uploaded_file() to move the temp file to the final location. All that works fine. In short, people are uploading files so everyone in the group can see them and the files are organized by the script.
My problem is that the file in the final location has odd permissions. It is not ending up with permissions from either the temp location or the final location. Both the temp location and final location have the same permissions: full rights for owner and administrations; read and read/execute for 2 specific AD security groups. The final file ends up with only: full rights for owner and administrations. So while the admins and the original uploader have no problem viewing the file, all others in the group get "permission denied" when trying to access it.
Any ideas or suggestions will be greatly appreciated! Thanks!
from the php page on move_uploaded_file (nb: this worked for me):
For those using PHP on Windows and IIS, you SHOULD set the "upload_tmp_dir" value in php.ini to some directory around where your websites directory is, create that directory, and then set the same permissions on it that you have set for your websites directory. Otherwise, when you upload a file and it goes into C:\WINDOWS\Temp, then you move it to your website directory, its permissions will NOT be set correctly. This will cause you problems if you then want to manipulate that file with something like ImageMagick's convert utility.
This seems to be an issue with the move_uploaded_file() function:
http://us3.php.net/move_uploaded_file
Take a look at the comments below, take note of Florian's comment about copy().
Would copy() solve the issue?:
http://us3.php.net/manual/en/function.copy.php

Categories