简体   繁体   中英

Cannot rename or delete files on ftp server with php

I wrote a php script locally on my machine that worked. But when I uploaded it too my ftp server i ran into some issues. Obviously I couldn`t use rename function etc, and had to change to ftp_rename etc. So the problem is that I can't rename or delete any files with my php script. I have tried to change permissions on files and root directory without any luck. I can browse the files, but not rename or delete them. I don't get any error messages either, the file doesn't load and I get a 500 server error if I try to rename or delete. Any suggestions?

$ftp_server = "";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, "username", "password");

$files = ftp_rawlist($ftp_conn, "www/subtitlesyncer/uploads");
ftp_delete($ftp_conn, "www/subtitlesyncer/uploads/newfile.txt")
if (ftp_rename($ftp_conn, "www/subtitlesyncer/uploads/newfile.txt","www/subtitlesyncer/uploads/new_file_edited.txt")) {
    ...
}

I use this settings, but can`t get any error.

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

This is the file I try to edit:

-rw-r--r-- 1 <username> <username> 130782 Sep 28 14:41 newfile.txt

I did set the permission on folder and subfiles and subfolders to 777 (for testing), but when I create the textfile it gets 644. But I've changed the permissions the textfile to 777 aswell, I still can`t delete it.

Make sure the file matches the permission for user and group that owns the file. If you are trying to delete it as user Apache in group Apache but your file owner is ftp_server in group ftp (or ant other not marching variation) you will have problems. Also, look for errors in your http error log for the particular server. There has to be something.

I stumbled upon this problem yesterday and checking out the error log of the ftp server solved my problem.

As you decribed I changed all permissions at the beginning, too. Unfortunately that didn't help me because I was creating a new destination folder when using ftp_rename() method, where I wanted to move some files.

It seems you have a different situation assuming the destination folder "www/subtitlesyncer/uploads" already exists.

For that reason please first try ftp_rename method with necessary slashes:

ftp_rename($ftp_conn, "/www/subtitlesyncer/uploads/newfile.txt", "/www/subtitlesyncer/uploads/new_file_edited.txt");

If it still does not proceed, try this command before executing ftp_rename:

ftp_chmod($ftp_conn, 0777, "www/subtitlesyncer/uploads/");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM