I try to upload a file through PHP's ftp_put function, like so:
ftp_put($this->conn_id, $rempath, $locpath, $mode);
However I get the error "Cannot STOR." Nothing more. The FTP-connection is OK since I can download files using the same settings and ftp_get(). The script should be OK as well since it works fine on my local setup but not on my public server.
What can I try to make it work? I Googled but found nothing of worth.
You should first check to make sure that you are able to upload using a regular FTP client. I see you say "there's no problem withmy FTP-client" but in the initial request you said you are able to download files successfully and failed to mention a successful upload. I believe you will find that uploading with a client will fail too because that message is the output of FTP and not PHP. Whether or not it is a permissions issue remains to be seen, but it is unlikely a PHP issue. Do a little more research on FTP error 550.
Sounds like a permissions error. Are you sure you have permissions to upload the file to the location you are trying to put it at? If you try to do the upload manually via FileZilla or something does it work?
You should check to be sure you have write permissions on the directory into which you are trying to put the file(s).
Cannot STOR is a permission issue. Doublecheck the permissions for the FTP user.
Related
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
Thanks
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
I have a script that uploads files to a directory with file permissions 0644. I am unable to delete the file via FTP or using PHP's unlink() function (550 error). After scouring the web, I was unable to find a method to fix this problem. I am aware that the issue has to do with group/owner permissions, but I don't know how to fix the problem.
Should I use copy() or rename() instead?
Any ideas?
Edit: All uploaded files have owner/group set as: 48 48. All other files that I have uploaded via FTP and NOT the PHP script are 1006 1006. Is the owner/group set for the incorrect user?
I have already tried using chmod() to set permissions to 0666. I think the problem may be with the user?
Edit 2: Should I use exec() and run a command that changes the owner and group of the file?
It depends on what user your script is running as. Try uploading the files as 0655 instead
if you're using move_uploaded_file(); function, permissions are set correctly, so unlink(); should work
try this
move_uploaded_file($from, $to);
chmod($to, 0666);
You will want to have write permission to delete the file. 6 represents read/write. The first number after the zero represents the file's owner, who created it. If you are running the script to create the file, you should be able to delete it as long as you use the same user, probably the server user.
I used to have a php file that does a simple move_uploaded_file by using selecting a local file and upload to our UNIX web server.
Now we migrate our code to a Windows2003 Server, then the move_uploaded_file() fails, the error that keeps coming up reads like:
"Cannot move the C:Windows\temp\100D.php" file to desiredDirectory.
here desiredDirectory means it caputures the correct directory for this file movement. The code we used is pretty straightforward:
if(move_uploaded_file($_FILES['file']['tmp_name'], $target))
and we did try change it to $HTTP_POST_FILES, but still not working.
So we are really clueless at the moment, wonder if any experts could give us some hints, thanks a lot.
You should check if the target directory exists and if the apache user has all rights on that folder.
For a test you can set the folder access settings for the user 'everyone' to 'full'
The snippet of your code i see here is correct and you don't have to use $HTTP_POST_FILES
Does the webserver have write permissions on the target directory? Given that you say the paths are correct, that's the other #1 major reason why file moves fail.
I've just created a php snippet that allows me to upload pictures. Im working on my personal pc that runs Windows7, IIS7 and PHP.
The wierd thing is that Im allowed to upload and it works great, but if i go to the folder: c:\inetpub\wwwroot\imgupload\uploads and try to view the image then im now allowed because i dont have any rights. Adding my user to file rights solves the problem but thats a bit silly aint it? im using php's move_uploaded_file()
any thoughts?
The webserver (IIS) and PHP run with different permissions as you yourself. It's the webserver that receives the file and writes it to disk. So it is entirely reasonable that someone else (i.e. you) does not have access to it.
The problem is that the 'user' creating the images isn't you, it is IIS. Consequently, you don't own the image, the server does.
You could try to do a chmod($file, 777); after the file has been created to make it publicly accesible.
I'm working on a upload script and using move_uploaded_file() function. The problem is, that it only works for .txt, .jpg, .psd and some other file types I've tryed, but not for .mp3, .mov, .avi and maybe others.
There is nothing to the script, it's just the function. An interesting thing is, that it doesn't show any error msgs, it just doesn't upload the file.
Does anybody have some experience with this problem?
Thanks, Mike.
I don't think this is actually down to file type, more to file size.
Create a PHP script that runs a <? phpinfo(); ?> and look out for the upload_max_filesize setting. It could be that it is something like 8 MB, causing all larger file uploads to fail.
If that is the case, you can try changing the setting using ini_set("upload_max_filesize", "3200000000"); for example. In most cases, if on a shared hosting package, that will probably not work, though. You may have to contact your hosting provider then.
You should also make your script throw reliable error messages. The attempt to upload a file that is too big usually shows up as an error when uploading the file. Check the Error Messages Explained chapter in the manual for the respective error codes and their meanings.