0

hello

I am trying to make a script that can upload multiple files (currently I set it to five).

I made the form look like this:

$i = 1;
            while ($i <= 5)
            {
$form .= "here goes the content of the form";
$i = $i + 1;
            }

I have three inputs in this form (title, description, file to be uploaded).

when the form submits the page that analyze the form looks like this:

$i = 1;
        while ($i <= 5)
        {
$imgtitle[$i] 	= $_post['$imgtitle[$i]'];
$imgdes[$i] 	= $_post['imgdesc[$i]'];
$file[$i] 	= $_files["cfile[$i]"]["tmp_name"];
$realname[$i] 	= $_files["cfile[$i]"]["name"];
$type[$i] 	= $_files["cfile[$i]"]["type"];
$size[$i] 	= $_files["cfile[$i]"]["size"];
$ext[$i]  	= strrchr($realname[$i],'.');

$i = $i + 1;
}

the problem is that all the values has empty values. I tried to work around this problem and did the following (take the image title as example):

$imgtitle 	= $_post['$imgtitle'];
$newtitle = $imgtitle[$i];

I came up with the title of the first image only.

any advice??

3
Contributors
7
Replies
9
Views
8 Years
Discussion Span
Last Post by diafol
0

It looks like the HTML you are outputting for your form must be incorrect Check that you are successfully outputting:

<input type="file" name="cfile[1]" />
<input type="file" name="cfile[2]" />
<input type="file" name="cfile[3]" />
<input type="file" name="cfile[4]" />
<input type="file" name="cfile[5]" />
0

hello

I am trying to make a script that can upload multiple files (currently I set it to five).

I made the form look like this:

$i = 1;
            while ($i <= 5)
            {
$form .= "here goes the content of the form";
$i = $i + 1;
            }

I have three inputs in this form (title, description, file to be uploaded).

when the form submits the page that analyze the form looks like this:

$i = 1;
        while ($i <= 5)
        {
$imgtitle[$i] 	= $_post['$imgtitle[$i]'];
$imgdes[$i] 	= $_post['imgdesc[$i]'];
$file[$i] 	= $_files["cfile[$i]"]["tmp_name"];
$realname[$i] 	= $_files["cfile[$i]"]["name"];
$type[$i] 	= $_files["cfile[$i]"]["type"];
$size[$i] 	= $_files["cfile[$i]"]["size"];
$ext[$i]  	= strrchr($realname[$i],'.');

$i = $i + 1;
}

the problem is that all the values has empty values. I tried to work around this problem and did the following (take the image title as example):

$imgtitle 	= $_post['$imgtitle'];
$newtitle = $imgtitle[$i];

I came up with the title of the first image only.

any advice??

Get rid of the single quote marks inside your post variables if you are placing a variable name in them => $_POST[$imgtitle]

$imgtitle[$i] 	= $_POST[$imgtitle[$i]];
$imgdes[$i] 	= $_POST['imgdesc[' . $i . ']'];
$file[$i] 	= $_FILES["cfile[" . $i . "]"]["tmp_name"];
$realname[$i] 	= $_FILES["cfile[" . $i . "]"]["name"];
$type[$i] 	= $_FILES["cfile[" . $i . "]"]["type"];
$size[$i] 	= $_FILES["cfile[" . $i . "]"]["size"];
$ext[$i]  	= strrchr($realname[$i],'.');
0

thanks for the help, but it still not working!!

I don't know what i am doing wrong; the form looks like this:

$i = 1;
            while ($i <= 5)
            {
                                
$repeat .="<tr>
<td width=\"10\" align=\"center\" class=\"stars\">*</td>
<td width=\"30%\" class=\"red_bold\">imgtitle :</td>
<td>
<b><input type='text' name='imgtitle[$i]' size='35' class=\"imglib_input_textbox\"></b></td>
						</tr>
						<tr>
<td width=\"10\" align=\"center\" class=\"stars\">*</td>
<td class=\"red_bold\">choose the photo :</td>
<td>
<input type='file' name='cfile[$i]' size='22' class=\"imglib_input_textbox\"></td>

</tr>
<tr>
<td valign=\"top\" width=\"10\" align=\"center\" class=\"stars\">*</td>
<td class=\"red_bold\" valign=\"top\">Description :</td>
<td>
<b>	<textarea rows='10' name='imgdesc[$i]' cols='42' class=\"imglib_input_textarea\"></textarea></b></td>
						</tr>
						<tr>
<td align=\"center\" colspan=\"3\">
<img border=\"0\" src=\"modules/gallery/themes/professional/spacer.gif\" width=\"1\" height=\"15\"><input type=hidden name=catno value='$cat'></td></tr>";
			$i = $i + 1;
            }

The code the analysis the form looks like this now:

$i = 1;
        while ($i <= 5)
        {
$imgtitle 	= $_POST[$imgtitle[$i]];
$imgdesc[$i] 	= $_POST['imgdesc[' . $i . ']'];

$file[$i] 	= $_FILES["cfile[" . $i . "]"]["tmp_name"];
$realname[$i] 	= $_FILES["cfile[" . $i . "]"]["name"];
$type[$i] 	= $_FILES["cfile[" . $i . "]"]["type"];
$size[$i] 	= $_FILES["cfile[" . $i . "]"]["size"];
$ext[$i]  	= strrchr($realname[$i],'.');
$size[$i] = $size[$i]/1024;
$ext[$i] = strtolower($ext);

echo "file: " . $file[$i] . "<br />";
echo "desc: " . $imgdesc[$i] . "<br />";
echo "type: " . $type[$i] . "<br />";
echo "size: " . $size[$i] ;
$i = $i + 1;
}

I had the same issue as before; when I remove [$i] from the variable and echo it later i get the first entry only.

0

Firstly, your HTML is a little wrong, you've used single quotes for your attribute values - use double quotes:

<input type='file' name='cfile[$i]' size='22' class=\"imglib_input_textbox\"></td>

should be

<input type=\"file\" name=\"cfile[]\" size=\"22\" class=\"imglib_input_textbox\"></td>

Also, take out your $i variable, just leave the square bracket empty. Successive cfiles will be incremented automatically (0 to 4 for 5 file widgets).

You then need to change $i intial value to 0.

[I][B]$i = 0;
        while ($i < 5)[/B][/I]
        {

$imgtitle 	= [I][B]$_POST[$imgtitle[$i]];[/B][/I]

//ARE YOU SURE ABOUT THE ABOVE LINE?? Looks wrong to me - shouldn't it be $_POST["imgtitle[" . $i . "]"]

[I][B]$imgdesc[$i] 	= $_POST['imgdesc[' . $i . ']'];
[/B][/I]
$file[$i] 	= $_FILES["cfile[" . $i . "]"]["tmp_name"];
$realname[$i] 	= $_FILES["cfile[" . $i . "]"]["name"];
$type[$i] 	= $_FILES["cfile[" . $i . "]"]["type"];
$size[$i] 	= $_FILES["cfile[" . $i . "]"]["size"];
$ext[$i]  	= strrchr($realname[$i],'.');
$size[$i] = $size[$i]/1024;
$ext[$i] = strtolower($ext);

echo "file: " . $file[$i] . "<br />";
echo "desc: " . $imgdesc[$i] . "<br />";
echo "type: " . $type[$i] . "<br />";
echo "size: " . $size[$i] ;
$i = $i + 1;
}
0

thanks again

here is how I have solved for any one who might find them useful:

imgtitle 	= $_POST["imgtitle"][$i];
$imgdesc = $_POST["imgdesc"][$i];

$file 	= $_FILES["cfile"]["tmp_name"][$i];
$realname 	= $_FILES["cfile"]["name"][$i];
$type 	= $_FILES["cfile"]["type"][$i];
$size 	= $_FILES["cfile"]["size"][$i];
0

Yes, nice one. Couldn't work out why we had to escape those counter variables - it looked all unnecessary

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.