Paras Kathiriya
Paras Kathiriya

Reputation: 27

Unable to download file using FTP, after upload file via PHP

I have written simple PHP code to upload image file. Images are uploading successfully.

Here is my code,

mkdir("uploaded images", 0777, true);
move_uploaded_file($sourcePath,$targetPathNew);

but when i download that image, it shows me Response: 550 Access is denied. Error: Critical file transfer error

enter image description here

Thanks

Upvotes: 2

Views: 1327

Answers (1)

astax
astax

Reputation: 1767

This is due to permissions of the file. The uploaded file is owned by a web server user (such as www-data) and your FTP server runs under different user. While you change permissions on the folder to 0777 (allow everything to everyone), the file doesn't inherit the same permissions.

To fix this, you probably can add chmod($targetPathNew, 0777) in your code after the move_uploaded_file(...).

There is a chance though that this won't work due to some stricter server configuration. I'm not going to dive into this as judging by your question you're not very familiar with the Linux permissions (sorry if I'm wrong). You can find some essential information about permissions here, for example - https://www.tutorialspoint.com/unix/unix-file-permission.htm

Upvotes: 2

Related Questions