Little Goat Posted May 9, 2006 Share Posted May 9, 2006 is there any way at all to select a folder in the file input?thnx. Link to comment Share on other sites More sharing options...
Chocolate570 Posted May 9, 2006 Share Posted May 9, 2006 Do you mean like, when the page is loaded, and the user clicks the browse button, a specific folder pops up? Link to comment Share on other sites More sharing options...
Little Goat Posted May 10, 2006 Author Share Posted May 10, 2006 no, actually I meant that instead of selecting files, the user could select folders. I don't want to upload them, I just need the filename. on another forum they told me it couldn't be done, so if no one answers, I'll assume it can't be done.LG Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 10, 2006 Share Posted May 10, 2006 Why do you want the foldername then? Tell me if I am wrong: you want users to upload files, and specify the foldername the files were in?I don't know if that is possible, but you do can just ask them to input the word .. :)Why do you need it Link to comment Share on other sites More sharing options...
skym Posted May 10, 2006 Share Posted May 10, 2006 I don't think it's possible to upload more than one file with only one <INPUT>.I can't even imagine the script which will handle the uploaded files. Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 10, 2006 Share Posted May 10, 2006 Multiple files do can be uploaded, using more inputs though. The code would only get exponentially more advanced ... Link to comment Share on other sites More sharing options...
scott100 Posted May 10, 2006 Share Posted May 10, 2006 no, actually I meant that instead of selecting files, the user could select folders.<{POST_SNAPBACK}> I don't think that's possible, you can only select one file per <input> no foldersmaybe i'm wrong but i doubt it, the name kinda gives it away: input type="file" Link to comment Share on other sites More sharing options...
Little Goat Posted May 10, 2006 Author Share Posted May 10, 2006 ok, all I want is an input with a browse button so that people can select a folder. all I need is THE NAME of the folder. I do not need anuything uploaded. as for what I am using it for, I have a php script that can show all the files and folders in a certain location. right now it only does the location of the script. I want it to do a folder that the user specifies by using the file input. maybe I should just have it start at the desktop and they can navigate to where they want to go. I guess it isn't possible.LG Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 10, 2006 Share Posted May 10, 2006 No it isn't, but you still can just ask for the name via a text input Link to comment Share on other sites More sharing options...
Little Goat Posted May 10, 2006 Author Share Posted May 10, 2006 yea, just trying to make it easier to findthe folder they want.thnx everybody.LG Link to comment Share on other sites More sharing options...
justsomeguy Posted May 10, 2006 Share Posted May 10, 2006 The client doesn't send that to the server, it only sends the name of the file itself. You might be able to use some javascript to send the name, but I'm not sure about that. But you might be able to use javascript to get the value of the file input element, if the value is the path then you can send that also. They would just have to select some file inside the folder, so you couldn't select an empty folder..Also, here's how you handle multiple file uploads in PHP, taken from the documentation: <form action="" method="post" enctype="multipart/form-data"><p>Pictures:<input type="file" name="pictures[]" /><input type="file" name="pictures[]" /><input type="file" name="pictures[]" /><input type="submit" value="Send" /></p></form><?phpforeach ($_FILES["pictures"]["error"] as $key => $error) { Â if ($error == UPLOAD_ERR_OK) { Â Â Â $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; Â Â Â $name = $_FILES["pictures"]["name"][$key]; Â Â Â move_uploaded_file($tmp_name, "data/$name"); Â }}?> Link to comment Share on other sites More sharing options...
Little Goat Posted May 10, 2006 Author Share Posted May 10, 2006 as far as I'm concerned this topic is finished. it may be closed.LG Link to comment Share on other sites More sharing options...
scott100 Posted May 10, 2006 Share Posted May 10, 2006 Wait, don't speak so soon I think i have managed it, only taken me over an hour to figure out the code I don't think you can choose a folder but if you chose a file the path to that file is inserted in the file box, from that javascript takes over1. choose a file2. click the button3. JavaScript chops of the start and end of path4. JavaScript takes the path and splits the backslashes5. obtain the last piece of text between the backslashes (your folder name)This script rocks, i love javascript <head><script>function delineate(str){var theleft = str.indexOf("\\") + 1;var theright = str.lastIndexOf("\\");var newString=(str.substring(theleft, theright));var splitText=newString.split("\\");var endCount=splitText.length;var total=0;for (count=0;count<endCount;count+=1){ total+=1;}total-=1;var folderName=splitText[total];alert("File is in: "+folderName+" folder");}</script></head><body><p>Choose a file: <input type="file" id="file" /></p><p>What folder was the file in? <br /><input type="button" value="Get Folder" onclick="delineate(file.value)" /></p><body> yyyippppppeeeeeeeeeee Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 11, 2006 Share Posted May 11, 2006 (edited) I'll be *** Congratulations, it works :)Exept, there has to be buildt in a form that actually accepts the file, but we know what you mean :blink:You mean more like this <html><head><title>Submit your file</title><script>function delineate(Form){ var str = Form.elements["file"].value; var theleft = str.indexOf("\\") + 1; var theright = str.lastIndexOf("\\"); var newString=(str.substring(theleft, theright)); var splitText=newString.split("\\"); var endCount=splitText.length; var total=0; for (count=0;count<endCount;count+=1) { total+=1; } total-=1; var folderName=splitText[total]; Form.elements["folder"].value = folderName;}</script></head><body><form name="SubmitFile" action="processform.php" method="post"><p>Choose a file: <input type="file" name="file" id="file" /></p><p>What folder was the file in? <br /><input type="hidden" name="folder" /><input type="submit" value="submit" onmousedown='delineate(document.forms[0]); return true' /></p></form></body></html> This code actually works like heaven lol :blink:If you click the submit button, both the file and the foldername get posted to processform.php Edited May 11, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
scott100 Posted May 11, 2006 Share Posted May 11, 2006 I'll be *** Congratulations, it works <{POST_SNAPBACK}> Ok course it works, i never post anything that doesn't Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 11, 2006 Share Posted May 11, 2006 Then check my little mod of it, that one does actually post the data to the next page, yours didn't :)It gets $_POST['file'] and $_POST['folder'] Link to comment Share on other sites More sharing options...
scott100 Posted May 11, 2006 Share Posted May 11, 2006 Then check my little mod of it, that one does actually post the data to the next page, yours didn't :)It gets $_POST['file'] and $_POST['folder']<{POST_SNAPBACK}> Ha ha your having a laugh, right? that was the easy bit, anyone could pass that information to php The hard bit was getting the folder name, not passing it :)Thank your for your modifcation though, i'm sure it works great Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 11, 2006 Share Posted May 11, 2006 I see you edited the text :)Don't downgrade me It was pretty hard to get the function to work :blink:lol Link to comment Share on other sites More sharing options...
Little Goat Posted May 14, 2006 Author Share Posted May 14, 2006 thanks, guys, I guess that is my only alternative.it's not really that important anyway. LG Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now