Old 06-29-2005   #1 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
Angry 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(&
#33;$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 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
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 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.
The Eagle is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-29-2005   #3 (permalink)
Registered User
 
ViciOuS's Avatar
 
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
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 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
The Eagle is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-29-2005   #5 (permalink)
Registered User
 
ViciOuS's Avatar
 
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 .
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-30-2005   #6 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to 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

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 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..
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-30-2005   #7 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
http://www.php.net/manual/en/features.file-upload.php <--i checked this out
may be the problem has solved,i will go try it ^^
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 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
The Eagle is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-30-2005   #9 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
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
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

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

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT