Jump to content

input type="file"


Little Goat
 Share

Recommended Posts

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

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

no, actually I meant that instead of selecting files, the user could select folders.

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

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

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

Wait, don't speak so soon :) I think i have managed it, only taken me over an hour to figure out the code :blink: 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 icon12.gif

<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 :):blink::)

Link to comment
Share on other sites

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 :blink:

<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 by Dan The Prof
Link to comment
Share on other sites

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']:)

Ha ha your having a laugh, right? icon5.gif 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 :blink:
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...