06-29-2005
|
#1 (permalink)
|
|
Invicible Snake
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668
|
Oh noooo!!!!What kind of problem is it???><
A question again...
i tried to make a upload form,a multiple once,just like www.photobucket.com
and heres my whole script:
PHP Code:
<script language="JavaScript">
****function increase()**{
************var num=document.form1.quantity.selectedIndex;
************document.form2.form_quant.value=num;
************document.form2.submit();
****}
</script>
<?
//GET THE QUANTITY OF FORMS-----------------------\
echo "<form method=post act='' name=form2>";
echo "<input type=hidden name=form_quant>";
echo "</form>";
$num=$_POST["form_quant"];
//----------------------------------------------------------/
if(!$_POST["submit"]) {
****echo "<form method=post enctype='multipart/form-data' name=form1 action='' >";
****echo "<select size='1' name='quantity' onChange='increase()'>
**************<option value='0'>choose the image quantity</option>
****************<option value='1'>1</option>
**************<option value='2'>2</option>
**************<option value='3'>3</option>
**************<option value='4'>4</option>
**************<option value='5'>5</option>
**********</select>";
****echo "<BR><BR>";
****if(!$num) { $num=1; }
****for($i=1;$i<=$num;$i++) {
********echo "Image $i <input type=file size=35 name='img[$i] '><BR>";
****}
****echo "<input type=file size=35 name='img'><BR>";
****echo "<input type=hidden name='MAX_FILE_SIZE' value='$size_bytes'>";
****echo "<input type=hidden name=image_quantity value='$num'>";
****echo "<BR><input type=submit name=submit value=submit>";
****echo "</form>";
}
else {
****$num=$_POST["image_quantity"];
****echo $num."<BR>";
****$dir="images/";
****$size_mb=5;
****$size_bytes = 5 * 1024 * 1024;
****for($i=1;$i<=$num;$i++) {
********echo $_FILES['img[$i]']['name']; //I`m trying to display the list of files`s name,but failed
****}
}
?>
I though i went to the right path till i meet up with this problem and everythings down,i spent almost 1 day on it,pls help me
__________________
|
|
|
06-29-2005
|
#2 (permalink)
|
|
Moderator
Join Date: Jul 2004
Location: Quebec City, Canada
Posts: 50
|
Well before you go any further, you'll have to add a enctype="multipart/form-data" attribute to your form element. That should be a step in the right direction.
The multipart/form-data encoding changes the way your form is submitted to the server, and allows for files to be uploaded.
|
|
|
06-29-2005
|
#3 (permalink)
|
|
Registered User
Join Date: Apr 2005
Posts: 82
|
He does have that in his form.
PHP Code:
if(!$_POST["submit"]) {
****echo "<form method=post enctype='multipart/form-data' name=form1 action='' >";
Although, in the first form for the 'get qnty of forms' your action is act=''. Shouldnt it be action='' ?
Also, your actions are set to nothing. Therefor the script is going to do nothing once the submit button is hit. (I may be wrong bcuz i don't know what your doing with that js.)
Try something like this...
PHP Code:
<?
// use any style you want, but this style
// breaks in and out of php to produce html.
/*----------------------------------------------*/
if(!$action)
{
?>
// define action as submit in url
<form action="?action=submit" method="post" enctype="multipart/form-data">
//input fields, selects, etc
</form>
<?
}
elseif($action == "submit")
{
?>
//define form values, and handle it
<?
}
?>
Last edited by ViciOuS; 06-29-2005 at 06:36 PM..
Reason: edited bottom script example
|
|
|
06-29-2005
|
#4 (permalink)
|
|
Moderator
Join Date: Jul 2004
Location: Quebec City, Canada
Posts: 50
|
Quote:
|
Originally Posted by ViciOuS
He does have that in his form.
|
You're right, I looked at the wrong form
The problem is not with the actions thought. If you leave the action="" empty, it will re-call the same page.
In fact, Para's problem lies within the way he names his files in his form. PHP does not accept file uploads that have array-like names, so instead of
PHP Code:
echo "Image $i <input type=file size=35 name='img[$i] '><BR>";
try
PHP Code:
echo "Image $i <input type=file size=35 name='img_$i'><BR>";
This particular case of php not being able to handle arrays has puzzled me a lot in the past, too
|
|
|
06-29-2005
|
#5 (permalink)
|
|
Registered User
Join Date: Apr 2005
Posts: 82
|
Quote:
|
Originally Posted by The Eagle
"The problem is not with the actions thought. If you leave the action="" empty, it will re-call the same page."
|
Wow.. I did not know that  .. But now I do!.. so thanks, as this will help me with future problems.
Also, I was wondering if PHP accepted arrays for filenames, and just bypassed it bcuz I didn't know for sure.. so thanks for setting me straight as well as parasnake  .
|
|
|
06-30-2005
|
#6 (permalink)
|
|
Invicible Snake
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668
|
It wont works,i dont know why,i`ve tried what Eagle said,but a little different,mine is
img."$i" (to connect text and var) but it seem awful so i did what Eagle said img_$i
but it wont appear anything
PHP Code:
if(!$_POST["submit"]) {
echo "<form method=post enctype='multipart/form-data' name=form1 action='' >";
echo "<select size='1' name='quantity' onChange='increase()'>
<option value='0'>choose the image quantity</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
</select>";
echo "<BR><BR>";
if(!$num) { $num=1; }
for($i=1;$i<=$num;$i++) {
echo "Image $i <input type=file size=35 name='img_$i '><BR>";
}
echo "<input type=file size=35 name='img'><BR>"; //just to test
echo "<input type=hidden name='MAX_FILE_SIZE' value='$size_bytes'>";
echo "<input type=hidden name=image_quantity value='$num'>";
echo "<BR><input type=submit name=submit value=submit>";
echo "</form>";
}
else {
$num=$_POST["image_quantity"];
echo $num."<BR>";
$dir="../images/";
$size_mb=5;
$size_bytes = 5 * 1024 * 1024;
for($i=1;$i<=$num;$i++) {
echo $_FILES['img_$i']['name'] ; //It still blank :(
}
echo $_FILES['img']['name']; //this test works perfectly,but these main part above are blank ><
}
[just to discuss]
About PHP wotn allow array in file name, i logged into www.photobucket.com and view source,theres form are named img[] ,isnt it an array???
[main problem]
pls help me....
__________________
Last edited by ParaSnake; 06-30-2005 at 06:31 AM..
|
|
|
06-30-2005
|
#8 (permalink)
|
|
Moderator
Join Date: Jul 2004
Location: Quebec City, Canada
Posts: 50
|
Quote:
|
Originally Posted by ParaSnake
It wont works,i dont know why,i`ve tried what Eagle said,but a little different,mine is img."$i" (to connect text and var) but it seem awful so i did what Eagle said img_$i but it wont appear anything
|
There appears to be two reasons why it doesn't work. First, in your form, you have an extra space in your name attributes:
name="img_1 "
On upload, this space is converted silently into an underscore by Firefox and maybe other browsers as well, so it's to avoid that practice. Second, at the line you said doesn't work, well... you have put img_$i between single quotes, se the $i isn't parsed ...
You're right about PHP accepting the array[] syntax. However you can't define the indexes manually, and this kind of spoils the fun sometimes
|
|
|
06-30-2005
|
#9 (permalink)
|
|
Invicible Snake
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668
|
well,i look up at php.net for help(as i posted above) and i`ve done it,thx 4 helping guys
@Eagle:maybe i will try it sometimes,my time is running out,i have to use php.net`s solution :P
__________________
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
|
Chicken & The Egg Problem!
|
Man1c M0g |
HTML / PHP / ASP / JS |
3 |
04-05-2005 07:02 PM |
|
redhat problem
|
Milkdrop |
General Discussions |
3 |
12-14-2003 08:05 AM |
All times are GMT +1. The time now is 05:55 PM. Content Relevant URLs by vBSEO 3.2.0
|