0

When I try to use ftp_delete() I get the error: Warning: ftp_delete(): File not found. My ftp server should be working fine, I can upload files fine to the same directory without a problem. Here is the PHP:

$fileSource = 'http://localhost/user/images/dfdf.png';
$ftpCon = ftp_connect('localhost');
ftp_login($ftpCon,'---','---');
ftp_delete($ftpCon,$fileSource);

Also when I look at the server logs I can see I get the message: 550 File not found

The url for $fileSource is the file's exact path, I went into localhost and copy/pasted it into the code, still for some reason it can't be found.

1
  • It's long since I last used php and I can't even remember for how long I haven't used php with ftp. But I think that the correct usage is ftp_delete(connection, path), where path is relative to ftp root, not as your $fileSource, which is URL. Commented Jul 12, 2014 at 22:31

1 Answer 1

1

The ftp_delete function acccepts a path to the file. You are providing http://localhost/user/images/dfdf.png which contains the host (http://localhost/). I think you mean to provide /user/images/dfdf.png, which is just the path.

Example:

 ftp_delete($ftpCon, '/user/images/dfdf.png');

When, for example, your FTP root is /user/, it will mean you need to provide ftp_delete with /images/dfdf.png. Thanks to @maremp.

Sign up to request clarification or add additional context in comments.

1 Comment

That is correct, if the ftp has same root directory as php server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.