Jump to content

Browsing for Empty Directory


OldManRiver

Recommended Posts

All,

 

Looking for a way to browse and get empty directory.  All the examples I see are using the:

<input type='file'>

with extra button, but that means you can not browse for an empty directory.

 

I'm sure there are good examples of this so would appreciate a quick shot with link to some source.

 

Thanks!

 

OMR

Link to comment
Share on other sites

Unfortunately neither PHP nor JavaScript can exercise any control whatsoever over where a user saves their downloads locally. This is completely the domain of the browser.

 

If this is crucial to your project and you have a captive user base you might consider writing a Firefox extension to do this for you and mandate your users use Firefox and install the extension. That's really the closest you can get, those limitations are designed into how the browser works for good reasons and there's not a way around them.

Link to comment
Share on other sites

jayarsee,

 

Sorry, you sure do not know your coding.  When creating a form the coder does have the opportunity to put in a path and send all files being downloaded to that directory and/or subdirectories there under.  I quess you never played with any of the FTP, SFTP or SCP functions that are available to you.

 

Cheers!

 

OMR

Link to comment
Share on other sites

We must simply be talking about completely different things. A user's download folder is a preference set by the user. A remote website can no easier tell a user where their download is going to go as it could remotely browse their file system. If there's a way to use the <form> tag to create directories on a user's local file system, you've got me dead to rights, I had no idea. And I've built massive data warehouse applications for Fortune 500 companies from scratch using PHP's FTP functions, thank you very much.

Link to comment
Share on other sites

jayarsee,

 

Well now that we are starting to get and understanding and yes <input type='text'> is in a form, I need to be able to browse for an empty directory with a "Browse" button on the form.

I have this code:

	 <input type='text' name='land' size='32'>
	 <input type='button' value='Browse' onClick='GetDirectory();'>

but the javascript I found for "GetDirectory()" assumed that I would use type='file' in my first input field, and just parses off the directory from there,  that method requires that there is at least one file in the directory to select.

 

There is a way, in javascript, and also in PHP to actually create/call a popup "Browse" window that just looks for a directory, which is what is needed when the directory you are searching for is empty.

 

That is my problem.  Slept since I did this about ten years ago, and forgot.

 

Thanks!

 

OMR

 

 

Link to comment
Share on other sites

Now I understand your request, it is possible to invoke a browse window using JavaScript. What I was saying, is that it is /not/ possible for a remote server to execute JavaScript, PHP, or any other function, outside of a browser extension, which automatically creates directories on a user's computer. You can prompt them to browse and they can /themselves/ create a directory, yes.

 

As far as prompting the user with a Browse window without the use of <input type='file' />, if there is a way, I have never heard of it. You can call click() actions on a hidden input type=file in order to simulate this behavior, but without a file input at all, not as far as I know.

 

I do know that since file type=input is a gateway into a user's filesystem browsers are /extremely/ strict about managing its behavior. For example, with few exceptions regarding visibility you can apply essentially no CSS to a file input. Some OSs treat directories like files when it comes to browse, so you could do it that way, but that's as far as anything I've ever seen goes. If that was a commonly available feature of JavaScript I feel like I would have seen it by now.

 

The closest implementation I can think of would be to have them select a file, and for browsers which report both the path and the file selected (some major ones don't), you could parse this value and remove the file portion of the string.

Link to comment
Share on other sites

Even if you could "capture" a directory location through a form input, you couldn't use it to actually start a download to that directory. Once a download is initiated control goes to the users system and the Browser/OS settings take over from there.

 

The only option I can think of would be to write a custom Java (not JavaScript) plug-in. Of course that would require the user to download and install that plug-in. Unless this is for an internal company solution where you could mandate something like that, the adoption rate of users who will install that plug-in will be low. Well, it *should* be low. I never install plug-ins unless I have 100% confidence in a site and even then I do some research to see if there is any information on the plug-in before I install it.

Link to comment
Share on other sites

  • 1 month later...

All,

 

You see forms that do this all the time.  I'm using the code:

	 $filn = $fdir.'\file'.$fcnt.'.html';

where $fdir is the directory and putting this together with:

ftp_get($rmt_con, $rm_file, $filn, FTP_ASCII);

where I download the files from the internet, so yes I am controlling the directory 100% and no OS has anything to do with what I am telling the system to do.

 

Thanks!

 

OMR

 

Link to comment
Share on other sites

Well, you did a piss poor job of explaining what you are trying to accomplish.

 

You stated that you wanted "the user" to select a directory. ftp_get() downloads a file from an FTP file onto the web server. If "the user" is selecting a folder to save a file using ftp_get() then you are apparently wanting the user to select a folder on the web server. I am assuming then, that "the user" is operating on the server. This is NOT the common configuration for a web application - the user is always assumed to be on a remote computer. You should have stated that the user was operating on the server and/or you wanted a remote user to select a folder on the server.

 

Perhaps instead of criticizing people for what you perceived to be a lack of ability, you should have taken a closer look at the responses and your requests. Then you might have identified that the problem was your inability to properly explain yourself.

 

I have an application for browsing/playing my mp3 collection and the management functionality has a feature that allows me to select the source folders for the mp3's on the server. Here is an old copy of that code, so it probably has some cleanup needed (and I have only used it on Windows, so not sure if it works on Linux).

 

<?php
session_start();
$drives_list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$_DS_ = DIRECTORY_SEPARATOR;

//Set the default drive
$drive='C';
if(isset($_POST['drive']) && strpos($drives_list, $_POST['drive'])!==false)
{
    $drive = substr($_POST['drive'], 0, 1);
    //Reset path
    $_SESSION['path'] = '';
}
else if(isset($_SESSION['drive']) && strpos($drives_list, $_SESSION['drive'])!==false)
{
    $drive = substr($_SESSION['drive'], 0, 1);
}

//Set the saved path
$savedPath = (isset($_SESSION['path'])) ? $_SESSION['path'] : '';
if(isset($_GET['updirectory']) && strpos($savedPath, $_DS_)!==false)
{
    $savedPath = substr($savedPath, 0, strrpos($savedPath, $_DS_, -2)+1);
}

//Set the newFolder directory
$newFolder = (isset($_GET['folder'])) ? $_GET['folder'].$_DS_ : '';

//Determin the current path
$path = '';
if(is_dir("{$drive}:{$_DS_}{$savedPath}{$newFolder}"))
{
    $path = $savedPath.$newFolder;
}
else if (is_dir("{$drive}:{$_DS_}{$savedPath}"))
{
    $path = $savedPath;
}

//Save current drive and path to session
$_SESSION['drive'] = $drive;
$_SESSION['path']  = $path;

//Create select options of valid drives
$drive_options = '';
for ($i=0; $i<strlen($drives_list); $i++)
{
    $drive_letter = $drives_list[$i];
    if (is_dir("{$drive_letter}:{$_DS_}"))
    {
        $selected = ($drive_letter==$drive)?' selected="selected"':'';
        $drive_options .= "<option value=\"{$drive_letter}\"{$selected}>{$drive_letter}:</option>\n";
    }
}

//Get the current folder path
$full_path = "{$drive}:{$_DS_}{$path}";

//Get the list of subfolders for the current folder
$folder_list = '';
$upDirectory = "<img style=\"border:0px;\" src=\"{$_PATHS['images']}up_directory.gif\" alt=\"Up One Directory\">Up One Directory";
if($path!='')
{
    $folder_list .= "<a href=\"{$_PATHS['current_web']}?action=browseFolder&updirectory=true\">{$upDirectory}</a><br />\n";
}
else
{
    $folder_list .= "<span style=\"font-style:italic;\">{$upDirectory}</span><br />\n";
}

$folders = glob($full_path."*", GLOB_ONLYDIR);
foreach($folders as $folderPath)
{
    $folder = substr($folderPath,  strrpos($folderPath, $_DS_)+1);
    $folderURL = rawurlencode($folder);
    $folder_list .= "<a href=\"{$_PATHS['current_web']}?action=browseFolder&folder={$folderURL}\">$folder</a><br />\n";
}

?>
<html>
<body>
<div style="width:300px;">
    <form name="drive_select" action="<?php echo $_PATHS['current_web'].'?action=browseFolder'; ?>" method="post">
    Drive:<br>
    <select name="drive" style="width:300px;align:right;" onchange="this.form.submit();">
      <?php echo $drive_options; ?>
    </select>
    </form>

    <form name="folder_select" action="<?php echo $_PATHS['current_web'].'?action=addFolder'; ?>" method="post">
    Current folder:
    <br />
    <textarea name="currentFolder" style="width:300;height:60px;background-color:#cecece;"><?php echo $full_path; ?></textarea>
    <br />
    Select a subfolder:
    <br />
    <div style="width:300px;height:200px;border:1px solid black;overflow:auto;padding:2px;">
    <?php echo $folder_list; ?>
    </div>
        <button type="submit" name="action" style="float:right;">Cancel</button>
        <button type="submit" name="action" style="float:right;">Add Current Folder</button>
    </form>
</div>
</body>
</html>

Link to comment
Share on other sites

mjdamato,

 

Loved your answer and have seen this with single input field and "Browse" button where click on button give pop-up with your "current path" and "directories" inputs, for selection, back to the main form, which is where I'm trying to get.  Was thinking it was done with call that opened this in Windows on that OS or other directory pop-up on Linux side.  Just do not remember if it was invoked with JavaScript or not.

 

Sorry about not describing the problem clearly; was clear to me.

 

Thanks!

 

OMR

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.