I'm not sure what you mean by FTP functions but with the phpinfo() command I got under 'Configure Command' there's a part that says '--enable-ftp' is that what you were looking for? It also shows up under 'Registered PHP Streams' and later on by itself it ways 'enabled'. So I guess that means, yes, it is enabled.
What I don't understand though is if I created those files with a script that the apache server runs then why when I use a script to delete them it says it's a different UID? Aren't they both Apache? Shouldn't they both be the same UID?
Do you know a way to get around this?
Ownership
Moderator: General Moderators
Fortunately for me I haven't had to deal too much with safe mode, but as a result I'm not quite sure as to why that a script that creates a file does not have permission to remove it.
I'm sure someone will correct me if I'm wrong (as I'm only guessing) but say if you are on a virtual server with multiple users like....
/home/auser/public_html/gallery/thumbs
/home/anotheruser/public_html/gallery/thumbs
Now if both users are using php to create their image thumbnails and php has no restrictions on file deletion then perhaps it would be possible for 'auser' to write a script which would delete files from 'anotheruser' directory. As both were created by php with owner set to 'apache'. It's just a guess but that would seem to make sense, comments/facts?
Anyway, you could try FTP to remove the files. I wrote a simple class for this for someone quite some time ago. Note it's nothing special but it does what it is supposed to do. I can't remember what state I left it in but I presume it still works.
class and example follow.....
And example usage....
I'm sure someone will correct me if I'm wrong (as I'm only guessing) but say if you are on a virtual server with multiple users like....
/home/auser/public_html/gallery/thumbs
/home/anotheruser/public_html/gallery/thumbs
Now if both users are using php to create their image thumbnails and php has no restrictions on file deletion then perhaps it would be possible for 'auser' to write a script which would delete files from 'anotheruser' directory. As both were created by php with owner set to 'apache'. It's just a guess but that would seem to make sense, comments/facts?
Anyway, you could try FTP to remove the files. I wrote a simple class for this for someone quite some time ago. Note it's nothing special but it does what it is supposed to do. I can't remember what state I left it in but I presume it still works.
class and example follow.....
Code: Select all
<?php
/**********************************************
* A simple FTP class to remove files and
* directories.
* to remove a file =
* myFTP_rmfile('path/to/file.file');
* path to file is from base_path e.g.
*
* base_path = '/public_html/images';
*
* To remove '/public_html/images/logo.jpg'
*
* myFTP_rmfile('logo.jpg');
*
* To remove '/public_html/images/more/logo.jpg'
*
* myFTP_rmfile('more/logo.jpg');
*********************************************
*/
class myFTP {
var $ftpvars; // array for server, user_name password etc...
var $conn_id; // connection id returned by ftp_connect
var $conn_log; // any messages to show at top of page
var $status; // FTP connection status true or false
var $response; // server response mimic
var $cwd; // current working directory
function myFTP($ftpvars) {
$this->ftpvars = $ftpvars;
$this->conn_id = false;
$this->conn_log = '';
$this->status = false;
$this->response = '';
$this->cwd = '/';
if($this->conn_id = $this->myFTP_connect()) {
$this->myFTP_login();
}
if($this->status) {
$this->_set_passive();
$this->_set_base_path();
}
}
function myFTP_connect() {
$this->conn_id = @ftp_connect($this->ftpvars['server']);
if($this->conn_id) {
$this->_add_conn_stat("<b>Connected</b> to {$this->ftpvars['server']}".
", for user {$this->ftpvars['user_name']}");
return true;
}else {
$this->_add_conn_stat("<b>Failed</b> to connected to {$this->ftpvars['server']}");
return false;
}
}
function myFTP_login() {
$result = @ftp_login($this->conn_id, $this->ftpvars['user_name'], $this->ftpvars['user_pass']);
if($result) {
$this->_add_conn_stat("<b>Password accepted</b> for user {$this->ftpvars['user_name']}");
$this->status = true;
return true;
}else {
$this->_add_conn_stat("<b>Failed</b> to authenticate user {$this->ftpvars['user_name']}");
$this->myFTP_close();
return false;
}
}
function myFTP_close() {
if($this->status) {
$result = @ftp_quit($this->conn_id);
if($result) {
$this->_add_conn_stat('<b>FTP Connection closed</b>');
$this->status = false;
return true;
}
}else {
$this->_add_conn_stat('<b>Call to close FTP Connection failed, connection allready closed</b>');
}
}
function myFTP_chdir($dir) {
if($this->status) {
$result = @ftp_chdir($this->conn_id, $dir);
$this->cwd = $this->_query_pwd();
if($result) return true;
return false;
}else {
$this->_addResponse('<b>Failed</b> to change directory, no FTP connection');
}
}
function myFTP_rmfile($file) {
if($this->status) {
$result = @ftp_delete($this->conn_id, $file);
if($result) {
$this->_addResponse("Delete {$file} successful");
return $result;
}else {
$this->_addResponse("Failed to delete {$file}");
return false;
}
}else {
$this->_addResponse("Failed to delete {$file} no FTP connection");
return false;
}
}
function myFTP_rmdir($dir) {
if($this->status) {
$result = @ftp_rmdir($this->conn_id, $dir);
if($result) {
$this->_addResponse("Delete directory ./{$dir} successful");
return $result;
}else {
$this->_addResponse("Failed to delete directory ./{$dir}");
return false;
}
}else {
$this->_addResponse("Failed to delete directory ./{$dir} no FTP connection");
return false;
}
}
function myFTP_get_conn_log() {
$log = $this->conn_log;
$this->conn_log = '';
return $log;
}
function myFTP_response() {
return $this->response;
}
function _set_passive() {
if($this->ftpvars['passive']) {
$result = @ftp_pasv($this->conn_id, true);
if($result) {
$this->_addResponse('Passive mode set');
}else {
$this->_addResponse('Failed to set passive mode');
}
}
return true;
}
function _set_base_path() {
if(isset($this->ftpvars['base_path'])) {
if($this->ftpvars['base_path'] != '/' || $this->ftpvars['base_path'] != '') {
if($this->myFTP_chdir($this->ftpvars['base_path'])) {
if($this->cwd != $this->ftpvars['base_path']) {
$this->_add_conn_stat('<b>Failed</b> to initialize working directory');
$this->myFTP_close();
}
}
}
}
}
function _query_pwd() {
if($this->status) {
$result = @ftp_pwd($this->conn_id);
return $result;
}
return false;
}
function _add_conn_stat($text) {
$this->conn_log .= $text . "\n<br>\n";
}
function _addResponse($text) {
$this->response .= $text . "\n<br>\n";
}
}
?>Code: Select all
<?php
$ftpvars['server'] = 'localhost'; // ftp server excluding the' ftp://'. localhost normally does the trick
$ftpvars['user_name'] = 'username'; // Your FTP login username
$ftpvars['user_pass'] = 'password'; // Your FTP password
$ftpvars['base_path'] = '/public_html/gallery/thumbs'; // Base directory no trailing slashes
$ftpvars['passive'] = false; // Set to true to enable passive mode
$ftp_funcs = @include('myftp.class.php');
if(!$ftp_funcs) {
echo 'Failed to load FTP functions.';
exit();
}
$ftp = new myFTP($ftpvars);
$ftp->myFTP_rmfile('an_image.jpg'); // removes file '/public_html/gallery/thumbs/an_image'
$ftp->myFTP_rmfile('another_image.gif');
$ftp->myFTP_rmfile('fullsize/an_image.jpg'); // removes file '/public_html/gallery/thumbs/fullsize/an_image'
$ftp->myFTP_rmfile('fullsize/another_image.gif');
$ftp->myFTP_rmdir('fullsize'); // removes the directory ''/public_html/gallery/thumbs/fullsize' (must be empty)
echo $ftp->myFTP_get_conn_log();
echo $ftp->myFTP_response();
$ftp->myFTP_close();
echo $ftp->myFTP_get_conn_log();
?>