By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,480 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,480 IT Pros & Developers. It's quick & easy.

How to access userfile names?

P: n/a
Don


The following 4 statements don't work. What is the proper way to
pickup the filenames corresponding to each of the userfiles in the
"input" tags? Thanks for your help. --Don

Following is part of a page that runs on the client side:
-----------------------------------------------------------------
var picture1 = document.forms.postamessagedata.userfile.name[0];
var picture2 = document.forms.postamessagedata.userfile.name[1];
var picture3 = document.forms.postamessagedata.userfile.name[2];
var picture4 = document.forms.postamessagedata.userfile.name[3];

Following is part of a form to be submitted to PHP upload processor
below. This resides in the same page as the foregoing.
--------------------------------------------------------------------------------
<p>Optional picture #1:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;
<p>Optional picture #2:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;
<p>Optional picture #3:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;
<p>Optional picture #4:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;

Following processes file uploads and resides on server:
-----------------------------------------------------------------
<?php
$uploaddir = 'picturevault/';
$uploadfile1 = $uploaddir . $_FILES['userfile']['name'][0];
$uploadfile2 = $uploaddir . $_FILES['userfile']['name'][1];
$uploadfile3 = $uploaddir . $_FILES['userfile']['name'][2];
$uploadfile4 = $uploaddir . $_FILES['userfile']['name'][3];

print "<pre>";

if ($_FILES['userfile']['size'][0] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][0],
$uploadfile1);

if ($_FILES['userfile']['size'][1] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][1],
$uploadfile2);

if ($_FILES['userfile']['size'][2] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][2],
$uploadfile3);

if ($_FILES['userfile']['size'][3] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][3],
$uploadfile4);

print "</pre>";

?>


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello

You will find this useful:

<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="lallous">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>

<script language="JavaScript">
<!--
function f1()
{
var f = document.f, e, s = '';
for (i=0;i<f.elements.length;i++)
{
e = f.elements[i];
x = e.name;
e = f.elements[i];
s += "i=" + i + " elements name='" + x + "' element value='" + e.value +
"'\n";
}
alert(s);
}
//-->
</script>
<body onload="f1();">
<form name="f">
<input type="text" name="f_t[]" value="1">
<input type="text" name="f_t[]" value="2">
<input type="text" name="f_t[]" value="3">
<input type="text" name="f_t[]" value="4">
</body>
</html>
p.s: you may replace the type="text" w/ type="file".
And to access its value you do it as: elementName.value.

--
Elias

"Don" <no@adr.com> wrote in message
news:lk********************************@4ax.com...


The following 4 statements don't work. What is the proper way to
pickup the filenames corresponding to each of the userfiles in the
"input" tags? Thanks for your help. --Don

Following is part of a page that runs on the client side:
-----------------------------------------------------------------
var picture1 = document.forms.postamessagedata.userfile.name[0];
var picture2 = document.forms.postamessagedata.userfile.name[1];
var picture3 = document.forms.postamessagedata.userfile.name[2];
var picture4 = document.forms.postamessagedata.userfile.name[3];

Following is part of a form to be submitted to PHP upload processor
below. This resides in the same page as the foregoing.
--------------------------------------------------------------------------------
<p>Optional picture #1:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;
<p>Optional picture #2:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;
<p>Optional picture #3:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;
<p>Optional picture #4:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;

Following processes file uploads and resides on server:
-----------------------------------------------------------------
<?php
$uploaddir = 'picturevault/';
$uploadfile1 = $uploaddir . $_FILES['userfile']['name'][0];
$uploadfile2 = $uploaddir . $_FILES['userfile']['name'][1];
$uploadfile3 = $uploaddir . $_FILES['userfile']['name'][2];
$uploadfile4 = $uploaddir . $_FILES['userfile']['name'][3];

print "<pre>";

if ($_FILES['userfile']['size'][0] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][0],
$uploadfile1);

if ($_FILES['userfile']['size'][1] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][1],
$uploadfile2);

if ($_FILES['userfile']['size'][2] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][2],
$uploadfile3);

if ($_FILES['userfile']['size'][3] != 0)
move_uploaded_file($_FILES['userfile']['tmp_name'][3],
$uploadfile4);

print "</pre>";

?>

Jul 23 '05 #2

P: n/a
lallous wrote:
Hello

You will find this useful:

<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="lallous">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>

<script language="JavaScript">
<script type="text/javascript">

The language attribute is deprecated.
<!--
Not required or desired.
e = f.elements[i];
x = e.name;
e = f.elements[i];
I'm not sure why you're grabbing a reference to the form element twice.
//-->
Not required or desired.
</script>
<body onload="f1();">
<form name="f">
You are missing a closing </form> tag.
</body>
</html>


<form>
<p>Optional picture #1:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;
<p>Optional picture #2:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;
<p>Optional picture #3:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;
<p>Optional picture #4:<br><input type=file name="userfile[]" size=90
maxlength=200000 tabindex=3>;

Read the values with:
<input type="button"
value="Show picture names (example only)"
onclick="showInputValuesOf(this.form, 'userfile[]');">
</form>

<script type="text/javascript">
function showInputValuesOf(f, inputName) {
var output = [];
var inputs = f.elements[inputName];
if (typeof inputs.length == 'undefined') {
inputs = [ inputs ];
}
for (var i = 0; i < inputs.length; i++) {
output.push(inputs[i].value);
}
alert(output.join('\n'));
}
</script>

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.