MikeDXUNL Posted March 26, 2007 Share Posted March 26, 2007 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 More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 $_FILES['photo'.$i.'] $_FILES['photo'.$i] $_FILES["photo".$i."] $_FILES["photo". $i] Those are correct ways to do it. Link to comment https://forums.phpfreaks.com/topic/44388-variable-inside-brackets/#findComment-215540 Share on other sites More sharing options...
MikeDXUNL Posted March 26, 2007 Author Share Posted March 26, 2007 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']); Link to comment https://forums.phpfreaks.com/topic/44388-variable-inside-brackets/#findComment-215546 Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 We need more code than that bud. Where is $photoreq being set? Where is the form? Link to comment https://forums.phpfreaks.com/topic/44388-variable-inside-brackets/#findComment-215551 Share on other sites More sharing options...
MikeDXUNL Posted March 27, 2007 Author Share Posted March 27, 2007 <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 Link to comment https://forums.phpfreaks.com/topic/44388-variable-inside-brackets/#findComment-215802 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.