Current location: Hot Scripts Forums » General Web Coding » HTML/XHTML/XML » How to populate an <input type="file" ..> box?


How to populate an <input type="file" ..> box?

Reply
  #1 (permalink)  
Old 06-09-04, 12:53 PM
cgott42 cgott42 is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
How to populate an <input type="file" ..> box?

I'm taking a different approach to a question I posted recently.
Now, I would like to know how to prepopulate the file input boxes for the user

Below is the code that I have:
It sets up 4 input boxes. I would like to populate all 4 boxes with:
c:\cdrombb\export\test1.txt
c:\cdrombb\export\test2.txt
c:\cdrombb\export\test3.txt
c:\cdrombb\export\test4.txt

when the user hits submit, it uploads all 4 files.

Any ideas on how to do this?

file: upload.php
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" enctype="multipart/form-data" method="post" action ="processFiles.php">
<p>

<?
// start of dynamic form
$uploadNeed=4;
for($x=0;$x<$uploadNeed;$x++){
?>
<input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>">

</p>
<?
// end of for loop
}
$uploadFile1_name = 'c:\CDROMBB\EXPORT\TEST2.txt';
?>
<p><input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>


file: processFiles.php
<?
$uploadNeed = $_POST['uploadNeed'];
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);
// check if successfully copied
if($copy){
echo "$file_name | uploaded sucessfully!<br>";
}else{
echo "$file_name | could not be uploaded!<br>";
}
} // end of loop
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shout box, comment box, or search script. Need help to find all! Spreegem Script Requests 1 05-29-04 10:45 PM


All times are GMT -5. The time now is 09:24 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.