?
Solved

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

Posted on 2003-02-19
5
Medium Priority
?
216 Views
Last Modified: 2006-11-17
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
Comment
Question by:ih8formvalidation
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 6

Expert Comment

by:carchitect
ID: 7986067
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
 
LVL 6

Expert Comment

by:carchitect
ID: 7991779
did you try that....
0
 

Author Comment

by:ih8formvalidation
ID: 7996126
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11810577
PAQed, with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question