bilis_money Posted June 12, 2006 Share Posted June 12, 2006 hi, these are my codes.[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- .box { font-family: Arial, Helvetica, sans-serif; font-size: 12px; border: 2px solid #000000; } --> </style></head><body bgcolor="#999999" text="#FFFFCC" leftmargin="0" topmargin="0"><div align="center"> <pre><font face="Georgia, Times New Roman, Times, serif"><strong>Uploading image files</strong></font> </pre><?php $uploadDir = $_SERVER['DOCUMENT_ROOT'].'/mygallery/upload/images/'; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile1']['name']; $tmpName = $_FILES['userfile1']['tmp_name']; $fileSize = $_FILES['userfile1']['size']; $fileType = $_FILES['userfile1']['type']; // the files will be saved in filePath $filePath = $uploadDir . $fileName; // move the files to the specified directory // if the upload directory is not writable or // something else went wrong $result will be false $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } include 'library/opendb.php'; if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $query = "INSERT INTO upload2 (name, size, type, path ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); include 'library/closedb.php'; echo "<br>File uploaded<br>"; }?><form action="" method="post" enctype="multipart/form-data" name="uploadform"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"><table><pre><tr><td><strong>Image 1.</strong> <input name="userfile1" type="file" class="box" id="userfile1" size="50"></td></tr><tr><td> <strong>Image 2.</strong> <input name="userfile2" type="file" class="box" id="userfile2" size="50"></td></tr><tr><td> <strong>Image 3.</strong> <input name="userfile3" type="file" class="box" id="userfile3" size="50"></td></tr><tr><td> <strong>Image 4.</strong> <input name="userfile4" type="file" class="box" id="userfile4" size="50"></td></tr><tr><td> <strong>Image 5.</strong> <input name="userfile5" type="file" class="box" id="userfile4" size="50"></pre><pre><tr><td><center> <input name="upload" type="submit" id="upload" value=" Upload "></center></td></tr></pre></table></form></div></body></html>[/code]what the codes does is to just upload files, very simple really.actually it has no error and it works very fine, as you notice only USERFILE1 is currently active and workingand not userfile2, userfile3 and soon.what i want to incorporate here is to make USERFILE2, 3, 4 and 5 active using looping while make the codesstay short.now, do i need to use while loop here? or for loop here? or should i create a function to do this or array?or else Class?i have no nice idea right now to make this happen, so i hope you help me with this.maybe a bright simple snippet of codes to show me on how to do this is very helpful?Thank you very much in advance. Quote Link to comment https://forums.phpfreaks.com/topic/11781-looping-the-upload-process/ Share on other sites More sharing options...
joquius Posted June 12, 2006 Share Posted June 12, 2006 first change userfile1-5 to userfile_1-5[code]for ($_POST as $name => $value){if (preg_match ("/userfile_[1-5]{1}/", $name)){ $name = explode ("_", $name); $num = $name[1]; $file = $value; //do stuff with these values}}[/code]this what u wanted? Quote Link to comment https://forums.phpfreaks.com/topic/11781-looping-the-upload-process/#findComment-44604 Share on other sites More sharing options...
bilis_money Posted June 12, 2006 Author Share Posted June 12, 2006 ok, thanks i'll try to figure out that.but if you still have cool logics other than this will be also appreciated.thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/11781-looping-the-upload-process/#findComment-44608 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.