Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65026 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86990 invoked from network); 18 Jan 2013 15:18:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jan 2013 15:18:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=wowkise@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=wowkise@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: wowkise@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:47759] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2C/27-24194-DD769F05 for ; Fri, 18 Jan 2013 10:18:53 -0500 Received: by mail-lb0-f170.google.com with SMTP id j14so2815683lbo.15 for ; Fri, 18 Jan 2013 07:18:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=UGYlUXGKwGNxb3EBhA6eFV9R5sAl4/wPQI/i06Ih8Sk=; b=hYlkXN4wcactwiaaslae3lYuh7FrbejCWA0edaZ4mCCVggt/ochfmTtRyEehx2dUSF UgDCa47uXB4ZrdHpTzcL0YEoGCmENptzFDsd466XoET0zgpDVF9TDQUzyrc/kY9ClVFF A6dN76tT85TuaPMD9c2u8YdFy556Lt0OGC+YjMmDW5zVuENMpLp/VlS4wUe+cHo+wjgK 4v12XezNHC1TfFcPyXERfTKURibSnZmCnbCEyE9A8YfyXbHxy4zvJ0kgpDhpHArSa6PO +YD2cTje0CN68d2ssECQLFvGZqiGqxrsUT6/lsmQ/9dLDGEz+cy64V6dv75zGBUgm4xh UWog== MIME-Version: 1.0 X-Received: by 10.112.82.202 with SMTP id k10mr3986542lby.22.1358522330251; Fri, 18 Jan 2013 07:18:50 -0800 (PST) Received: by 10.112.76.229 with HTTP; Fri, 18 Jan 2013 07:18:50 -0800 (PST) In-Reply-To: References: <3F59B8D4-01A9-4B97-89D0-4DC21B58F1C0@php.net> Date: Fri, 18 Jan 2013 18:18:50 +0300 Message-ID: To: Paul Dragoonis Cc: Will Fitch , PHP Internals List Content-Type: multipart/alternative; boundary=bcaec5555402ea01a904d391a074 Subject: Re: [PHP-DEV] new FTP function From: wowkise@gmail.com (KISE) --bcaec5555402ea01a904d391a074 Content-Type: text/plain; charset=ISO-8859-1 Will Fitch, sorry i didn't know that i contacted one of the dev to post it on behalf of me and he said its ok to post here, i'll post it there right away Paul Dragoonis, there is 3 ways to do it in userland codes. Public function dir_exists($dir) { if (!$this->conn_id) return false; $currentDir = ftp_pwd($this->conn_id); if ( ftp_chdir($this->conn_id, $dir) ) { ftp_chdir($this->conn_id, $currentDir); return true; } return false; } this function above attempts to change directory it see if its exists or not. and produce E_WARNING if the dir doesn't exists and there is echo ( is_dir("ftp://{$username}:{$password}@{$server}{$dir}") ) ? true : false; which require that you re-authenticate Public function dir_exists2($dir) { if ( !$this->conn_id ) return false; $orginal = $dir; if ( substr($dir, -1) === '/' ) $dir = substr($dir, 0, strlen($dir)-1); $dir = substr($dir, 0, strlen($dir)-strlen(strrchr($dir,'/'))); $res = ftp_nlist($this->conn_id, '-dF '. $dir); if ( isset($res) AND is_array($res) ) { foreach ($res as $key => $value) { if ($value === $orginal) return true; } } return false; } this function i hacked my self to stop the E_WARNING from flooding my error log files. it works but kinda ugly and so hackish, and i dont think it will work nicely if there is too many directories. On Fri, Jan 18, 2013 at 6:04 PM, Paul Dragoonis wrote: > I don't believe there's a feature of the FTP protocol to check if a > file/folder exists. > > Can you please provide a PHP userland solution to this, so that a > corresponding C implementation could be added. > > I believe the way to go about it is list the CWD contents and check if > that exists and is of type DIR. You must also make sure that if a file > exists with the name of the directory you want to check it has to handle > that properly, it can't simply return true or false. If false then that > means you could create it because it doesn't exist. If true it means you > can CD into it and put stuff there, which is also not true. > > Thanks, > Paul. > > > On Fri, Jan 18, 2013 at 3:00 PM, Will Fitch wrote: > >> >> On Jan 18, 2013, at 9:53 AM, KISE wrote: >> >> > Hi >> > >> > II would like to see "ftp_dir_exists()" function in PHP, right now its >> > kinda unreasonable to expect people to use hacks such as "is_dir()" and >> > having to re-authenticate just to check if the dir exists, I also dont >> > think its good idea to use "ftp_chdir()" just to check if the directory >> > exists, because its shows errors if the directory doesn't exists. i >> think >> > there should be a way to check if the directory exists without having to >> > resort to hackish ways, or having to authenticate again. >> >> There are procedures in place for this. If you'd like to make a feature >> request, use bugs.php.net and submit the request with the FTP extension >> selected. You can also use https://wiki.php.net/rfc if you really want >> to see/make the change as well. > > > --bcaec5555402ea01a904d391a074--