Jump to content

Ftp upload and delete problem


sniperscope

Recommended Posts

hi,

i have little problem with ftp

below script creates folder with valid ownership.

 

$file_name = $_POST['name'];	

$path = "/public_html/img/stuff/" .$file_name;

$conn = ftp_connect("ftp.co.jp") or die("Could not connect");

ftp_login($conn,"japan","123456");

ftp_mkdir($conn, $path);

ftp_close($conn);

but when try to upload and/or delete a file i got error such as file not found.

 

here is upload file code for upload.php.

$name = $_POST['name'];
  	// Configuration - File type Options
      $allowed_filetypes = array('.jpg','.gif','.png'); 
      $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
      $upload_path = '../img/stuff/'.$name; // The place the files will be uploaded to (currently a 'files' directory).
	  $upload_path = $upload_path.'/';

   $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
  
  
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
	  die('The file you attempted to upload is too large.');

   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)){
		 header ('location: index.php.php');
	 } else {
		 echo 'There was an error during the file upload.  Please try again.';
	}

 

and here is the folder deletion code for delete_folder.php.

 

	$name = $_POST['name'];

if(!file_exists($path = ("../img/stuff/".$name))){
	echo "File Not Found";
} else {
	$path = ("../img/stuff/".$name);

	$origipath = $path;
	$handler = opendir($path);
	while (true) {
		$item = readdir($handler);
		if ($item == "." or $item == "..") {
			continue;
		} elseif (gettype($item) == "boolean") {
			closedir($handler);
			if (!@rmdir($path)) {
				return false;
			}
			if ($path == $origipath) {
				break;
			}
			$path = substr($path, 0, strrpos($path, "/"));
			$handler = opendir($path);
		} elseif (is_dir($path."/".$item)) {
			closedir($handler);
			$path = $path."/".$item;
			$handler = opendir($path);
		} else {
			unlink($path."/".$item);
		}
	}
		return true;
		//echo "Folder was Deleted succesfully";
}

delete_folder.php seems work good but when i check the folder via FTP program i see the folder and whole files still there.

i am totally desperate. Where and what am i doing wrong ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.