Jump to content

variable inside brackets...?


MikeDXUNL

Recommended Posts

I want $i to be inside $_FILES['photo'],

 

right after photo so I changes to photo1, photo2, photo3 each time.

 

i already made the statement, but it won't increase the number

 

i have tried:

$_FILES['photo ".$i."']

$_FILES['photo "$i"']

$_FILES['photo .$i.']

 

any help is appreciated :)

Link to comment
https://forums.phpfreaks.com/topic/44388-variable-inside-brackets/
Share on other sites

it gives me an error on line 71.

 

$photoreq is the field that needs to be filled

 

the rest are optional. that is why they are photo1,2,3,4,etc..

 

 

 

here is my code:

if (!is_uploaded_file($photoreq['tmp_name'])) {
    $error = "you didn't select a file to upload.<br />";
//Check if file is within size range
} else {
    if ($photoreq['size'] > $maxfilesize) {
        $error = "your image file was too large.<br />";
        unlink($photo1['tmp_name']);
    } else {
//Check if file extension is correct
        $ext = strrchr($photoreq['name'], ".");
        if ($ext != ".gif" AND $ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".bmp" AND $ext != ".GIF" AND $ext != ".JPG" AND $ext != ".JPEG" AND $ext != ".BMP") {
            $error = "your file was an unacceptable type.<br />";
            unlink($photoreq['tmp_name']);
//If all checks OKAY, upload and replace photo
        } else {
            $newname = $firstname. "_" .$lastname. randomkeys(1) .$ext;
            move_uploaded_file($photoreq['tmp_name'],"images/".$newname);
      	    }
	}
#######################################################
//start loop
$i=1;
while($i<=12)
  {
  //Check if file was uploaded
    if ($_FILES['photo'.$i]['size'] > $maxfilesize) {
        $error = "your image file was too large.<br />";
        unlink($_FILES['photo'.$i]['tmp_name']);
    } else {
//Check if file extension is correct
        $ext = strrchr($_FILES['photo'.$i]['name'], ".");
        if ($ext != ".gif" AND $ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".bmp" AND $ext != ".GIF" AND $ext != ".JPG" AND $ext != ".JPEG" AND $ext != ".BMP") {
            $error = "your file was an unacceptable type.<br />";
            unlink($_FILES['photo'.$i]['tmp_name']);
//If all checks OKAY, upload and replace photo
        } else {
            $newname = $firstname. "_" .$lastname. randomkeys(1) .$ext;
            move_uploaded_file($_FILES['photo'.$i]['tmp_name'],"images/".$newname);
      	    }
	}
};
  $i++;
//end loop
#######################################################
}

 

 

  70        $error = "your file was an unacceptable type.<br />";
    71        unlink($_FILES['photo'.$i]['tmp_name']);

<form action="uploadpicsOKOLD.php" method="post" enctype="multipart/form-data">
**First Name: <input type="text" size="25" maxlength="25" name="firstname" /><br />
**Last Name: <input type="text" size="25" maxlength="25" name="lastname" /><br />
**Email: <input type="text" size="25" maxlength="25" name="email" /><br />
Website: <input type="text" size="25" maxlength="25" name="website" /><br /><br /><br />

Image-Upload: <input type="file" name="photoreq">
<table class="footcollapse">
<thead>
	<tr>
		<th></th>

	</tr>
</thead>

<tfoot>
	<tr>
		<th> </th>
		<td colspan="2"> </td>
	</tr>
</tfoot>
<tbody>
	<tr>

		<th>Image-Upload: </th>
		<td><input type="file" name="photo"></td>
		<td> </td>
	</tr>
	<tr class="odd">
		<th>Image-Upload: </th>
		<td><input type="file" name="photo"></td>
		<td> </td>
	</tr>
	<tr>
		<th>Image-Upload: </th>
		<td><input type="file" name="photo"></td>
		<td> </td>
	</tr>

	<tr class="odd">
		<th>Image-Upload: </th>
		<td><input type="file" name="photo"></td>
		<td> </td>
	</tr>
	<tr>
	<th>Image-Upload: </th>
		<td><input type="file" name="photo"></td>
		<td> </td>
	</tr>
</tbody>
</table>
<input type="submit" value="Upload Photo(s)">
</form>

 

that is the uploadpics.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.