473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to access userfile names?

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
2 1783
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ralfthewise | last post by:
Is there any way to prevent the $_FILES from being modified by PHP? For instance, if somebody puts "http://groups-beta.google.com/group/comp.lang.php" in the edit box for an uploaded file,...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
1
by: Andrew Arace | last post by:
I scoured the groups for some hands on code to perform the menial task of exporting table data from an Access 2000 database to Oracle database (in this case, it was oracle 8i but i'm assuming this...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
2
by: Dutchy | last post by:
Hi there, After spending several hours trying all I could imagine and search for in Google I gave up. In a continuous form I want to sort the choosen column by clicking the header (label) of...
3
by: dale zhang | last post by:
Hi, I am trying to read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp The article author is using PictureBox for windows...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
3
by: lister | last post by:
Hi, I am in the middle of writing an image upload script and am limiting the size of uploads via upload_max_filesize. This all seems to be working well, and if I try and upload a bigger file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.