Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

How do I get the values from value[$i]?

Basically I need a function that allows a member to post 1-5 files and then INSERT the path and filename to a mysql database. and The way I see it is every single image uploaded is renamed $newfile. SO, how do I get specific file names from 1-5?

Thanks in advance!

<?php
numoffile = 5;

define(PATH, "PATH HERE");
     
     if (!$dir = @opendir(PATH.$userid))
     mkdir(PATH.$userid, 0775) or die("<b>Error:</b> could not make directory.");
 
    for ($i=0;$i<$numoffile;$i++) {
      if (trim($_FILES['myfiles']['name'][$i])!="") {
        $newfile[$i] = $_FILES['myfiles']['name'][$i];
        move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], PATH.$newfile[$i]);
        $j++;
      }
    }
  if (isset($j)&&$j>0) print "Your file(s) has been uploaded.<br>";
  print "<form method='post' enctype='multipart/form-data'>";
  for($i=0;$i<$numoffile;$i++) {
    print "<input type='file' name='myfiles[]' size='30'><br>";
  }
  print "<input type='submit' name='action' value='Upload'>";
  print "</form>";
}
0
ih8formvalidation
Asked:
ih8formvalidation
  • 2
1 Solution
 
carchitectCommented:
hey why don't you do it in simple manner
make 5 file upload buttons in one form and in form handler do coding...

hey got it
here is your code which is working


make first file fileupload.php assign necessary vales to yur variables like PATH and userid as i changed it for testing.......

<?php
$numoffile = 5;
print "<form method='post' action=fileupload5.php enctype='multipart/form-data'>";
 for($i=0;$i<$numoffile;$i++) {
   print "<input type='file' name='myfiles[]' size='30'><br>";
 }
 print "<input type='submit' name='action' value='Upload'>";
 print "</form>";
?>


second file......
fileupload5.php

<?php
$numoffile = 5;
$userid="uu1";
$PATH="./";
   
if (!$dir = @opendir($PATH.$userid))
mkdir($PATH.$userid, 0777) or die("<b>Error:</b> could not make directory.");

for ($i=0;$i<$numoffile;$i++) {
if (trim($_FILES['myfiles']['name'][$i])!="") {
$newfile[$i] = $_FILES['myfiles']['name'][$i];
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $PATH.$userid."/".$newfile[$i]);
$j=1;
}
}
 if (isset($j) && ($j==1)) print "Your file(s) has been uploaded.<br>";
?>



this code is working i have checked it....
regards
0
 
carchitectCommented:
did you try that....
0
 
ih8formvalidationAuthor Commented:
Thanks for your time but I fixed it. I just realized to use the newfile[$i] fields as newfile[1] etc. when I place it in my database
0
 
moduloCommented:
PAQed, with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now