473,387 Members | 1,492 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,387 software developers and data experts.

multi-file upload - $_POST not working...

Ben
Hi everybody!
I have a multi-file upload form... Please looks at my code below. It's
in an initial stage. I'm trying to display the values of each text box
when I press "upload" but it doesn't seem to work... i don't know
what's the problem.. I'm using PHP5.

<html>
<head>
</head>
<body>
<?php
function ifcond($i) {
if ($i > 9) {
return $i;
}
else {
return '0'.$i;
}
} //end function ifcond()
for ($i=1; $i < 11; $i++) {
$image[$i - 1] = $_POST[`echo 'image'.ifcond($i);`];
}
print_r($image);
?>

<form action="<?php echo $_SERVER['../PHP_SELF']; ?>"
method="post">
<?php
for ($i=1; $i < 11; $i++) { ?>
Image<?php echo ifcond($i); ?>:
<input type="file" name="image"<?php echo ifcond($i); ?> /><br /><br
/>
<?php } ?>
<input type="submit" value="Upload" /></p></form>
</form>
</body>
</html>

Thanx!
Ben
Jul 17 '05 #1
6 2667
*** Ben wrote/escribió (22 Sep 2004 23:53:06 -0700):
I have a multi-file upload form... Please looks at my code below. It's
in an initial stage. I'm trying to display the values of each text box
when I press "upload" but it doesn't seem to work... i don't know
what's the problem.. I'm using PHP5.


I can't figure out what this code is supposed to do, I'd bet that it
doesn't even output valid HTML:

<input type="file" name="image"1 /><br /><br />
<input type="file" name="image"2 /><br /><br />
<input type="file" name="image"3 /><br /><br />
<input type="file" name="image"4 /><br /><br />
<input type="file" name="image"5 /><br /><br />

--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
Jul 17 '05 #2
On Wed, 22 Sep 2004 23:53:06 -0700, Ben wrote:
Hi everybody!
I have a multi-file upload form... Please looks at my code below. It's
in an initial stage. I'm trying to display the values of each text box
when I press "upload" but it doesn't seem to work... i don't know
what's the problem.. I'm using PHP5.

I haven't studied this in detail enough to know exactly where your problem
is, but I can see one problem right away. You have one misplaced quotation
mark, namely the one after image on this line:
<input type="file" name="image"<?php echo ifcond($i); ?> /><br /><br


I believe you want the return from function ifcond to be attached to the
word image, not come after it in the input tag.

But more importantly, you should try to rewrite your code so that it is
more readable. I very rarely mix clear html text with php tags for the
very reason that your piece of code here is very hard to debug. There are
many ways to write this piece of code, some more efficient than others,
but forgetting efficiency for the moment (php is fast anyway), this might
read better instead of the equivalent lines that you wrote:

<?php
for ($i=1; $i < 11; $i++)
{
$str = ifcond($i);
echo "Image$str:<input type=\"file\"
name = \"image$str\" /><br /><br />";
}
?>

Granted, it is clumsy having to use \" within to write a quote within the
echo command, but it reads better than having to parse a handful of php
tags by eyeball. Note here also, you have only one call to your function
instead of two. Also, if you are using a php-syntax aware editor,
something like Image$str looks very readable since the $str will be taken
as a PHP variable and made in a different color than Image.

Regards,
Steve, Denmark
Jul 17 '05 #3
As an afterthought to my reply, even better would be to use the following
construct, making your function ifcond unnecessary. If you get used to
the " if () ? true : false " syntax, things get a lot easier:

<?php
for ($i=1; $i < 11; $i++)
{
$str = ($i < 10) ? "0$i" : $i;
echo "Image$str:<input type=\"file\"
name = \"image$str\" /><br /><br />";
}
?>


Regards,
Steve, Denmark

Jul 17 '05 #4
Ben
coolsti <co*@goontrytospamme.com> wrote in message news:<pa****************************@goontrytospam me.com>...
As an afterthought to my reply, even better would be to use the following
construct, making your function ifcond unnecessary. If you get used to
the " if () ? true : false " syntax, things get a lot easier:

<snip>

thanx for tips steve..

i managed to find the problem... Have a look at the code below... The
reason "print_r($image);" doesn't show the selected items is
something to do with enctype="multipart/form-data". If I remove the
"enctype=....", "print_r($image);" displays the selected items.. But I
don't know the real relationship behind $_POST and enctype. Maybe
someone can explain me... I think the easier and a better way is to
use $_FILES with an array for "name" as in: <input type="file"
name="image[]">
<html>
<head>
</head>
<body>
<?php
for ($i=1; $i < 11; $i++) {
$str = ($i < 10) ? "0$i" : $i;
$image[$i - 1] = $_POST["image".$str];
}
print_r($image);
echo "<br />";
print_r($_FILES);

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>"
enctype="multipart/form-data" method="post">
<?php
for ($i=1; $i < 11; $i++) {
$str = ($i < 10) ? "0$i" : $i;
echo "Image$str:<input type=\"file\" name=\"image$str\" /><br
/><br/>";
} ?>
<input type="submit" value="Upload" /></p></form>
</form>
</body>
</html>

Ben
Jul 17 '05 #5
thanx for tips steve..


Have you read the PHP documentation (google search for "php documentation"
and take the first link) on file uploads? This explains pretty much how
things work, and yes, I believe when you do a file upload, your file names
are found in the $_FILES array. Note that your files are stored on your
server while the script is running with php-given temperary names in some
temperary directory, but you can access all this information using
$_FILES, see documentation. You need to do something with your uploaded
file before your upload script ends, e.g. move the temporary uploaded
files to more permanent locations, or they will disappear.

Regards,
Steve

Jul 17 '05 #6
> > I have a multi-file upload form... Please looks at my code below. It's
in an initial stage. I'm trying to display the values of each text box
when I press "upload" but it doesn't seem to work... i don't know
what's the problem.. I'm using PHP5.


I haven't studied this in detail enough to know exactly where your problem
is, but I can see one problem right away. You have one misplaced quotation
mark, namely the one after image on this line:
<input type="file" name="image"<?php echo ifcond($i); ?> /><br /><br


Sorry to reply to this message, but I'm unable to view the original message.

You can actually do this:
<input type = "file" name = "userfile[]" />
<input type = "file" name = "userfile[]" />
<input type = "file" name = "userfile[]" />
<input type = "file" name = "userfile[]" />
<input type = "file" name = "userfile[]" />

and in your PHP code do this:

foreach($_FILES['userfile']['name'] as $key=>$val) {
echo "NAME OF FILE ".$key.": ".htmlentities($val)."<br />\n";
echo "TMPNAME OF FILE ".$key.":
".htmlentities($_FILES['userfile']['tmp_name'][$key])."<br /><br />\n\n";
//do your validation and stuff
}

And that way you don't have to deal with missing files (like if there are 10
fields and the user selects files in 1,2,3,6,7 and 8.

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: OutsiderJustice | last post by:
Hi All, I can not find any information if PHP support multi-thread (Posix thread) or not at all, can someone give out some information? Is it supported? If yes, where's the info? If no, is it...
37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
14
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
As far as I know, the C Standard has no mention of multi-threaded programming; it has no mention of how to achieve multi-threaded programming, nor does it mention whether the language or its...
4
by: =?Utf-8?B?SGVucmlrIFNjaG1pZA==?= | last post by:
Hi, consider the attached code. Serializing the multi-dimensional array takes about 36s vs. 0.36s for the single-dimensional array. Initializing the multi-dimensional array takes about 4s...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.