PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Fri Mar 04, 2005 4:15 am
Here's my form that displays 15 file fields.
Code: Select all
<form action="dcamset.php?password=password&camset=<? echo $camset; ?>" method="post">
<input type="hidden" name="action" value="adddpicture">
<? for($i=0; $i<15; $i++){ ?>
<input type='file' name='filetouploadї]' size='20'><BR><? } ?>
<input type="submit" value="Upload Pictures">
</form>
I need tips/suggestions on how to turn the following code into one that will iterate through the files uploaded until it is finished:
Code: Select all
if($action == "adddpicture"){
$upload_dir = "digital/$camset/";
if(is_writable($upload_dir)){ echo "Is Writeable"; } ELSE { echo "Not Writeable"; }
if(is_uploaded_file($_FILESї'filetoupload']ї'tmp_name'])) {
$filename2 = $_FILESї'filetoupload']ї'name'];
$extension = strtolower(strrchr($filename2,"."));
$extensions = array('.jpg','.jpeg','.png');
if(!in_array($extension, $extensions)) { echo "File type not allowed."; }
$rand = rand(0,9999999999);
$filename = $rand.$extension;
if(move_uploaded_file($_FILESї'filetoupload']ї'tmp_name'],$upload_dir.$filename)) {
include 'createthumb.inc.php';
createthumb("digital/$camset/$filename","digital/$camset/thumbs/$filename",100,100);
$insertsql = "INSERT INTO digitalfiles (filename, camsetid) VALUES('$filename', '$camset')";
mysql_query($insertsql) or die(mysql_error()); } ELSE {
echo "There was a problem moving your file"; } } }
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 04, 2005 7:55 am
each element of the $_FILES['filetoupload'] variable is an array now.. one for each file upload field I believe.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Fri Mar 04, 2005 8:11 am
Alright, so I now have $_FILES['filetoupload'][1] through 15
Code: Select all
for($_FILESї'filetupload'] = 0; $_FILESї'filetoupload'] < 15; $_FILESї'filetoupload']++){
// upload code here
}
would work?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 04, 2005 8:13 am
no.
print_r($_FILES['filetoupload'])
you'll see what I mean.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Fri Mar 04, 2005 3:05 pm
I understand what you mean. It will return an array with elements such as [size] [type] etc.
How will this help me iterate through the upload code?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 04, 2005 3:20 pm
Code: Select all
$keys = array_keys($_FILESї'filetoupload']);
foreach($_FILESї'filetoupload']ї'name'] as $n => $name)
{
$filedata = array();
foreach($keys as $key)
$filedataї$key] = $_FILESї'filetoupload']ї$key]ї$n];
processFile($filedata);
}you can figure out what goes in processFile()
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Fri Mar 04, 2005 3:34 pm
haha I can?
I checked php.net for processFile
couldn't find it...
I'm a bit on the uneducated side.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 04, 2005 3:39 pm
it's a user defined function... it contains your upload processing code.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Fri Mar 04, 2005 3:41 pm
ah I gotchya!
thanks much.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Fri Mar 04, 2005 3:47 pm
I'm not quite sure how I would do this
Code: Select all
function processFile($filedata){
// upload code here//
}
processFile($_FILESї'filetoupload']ї$key]ї$n]
?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 04, 2005 3:50 pm
read the code I posted again..
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Fri Mar 04, 2005 3:54 pm
yes I know
I would have this:
Code: Select all
$keys = array_keys($_FILESї'filetoupload']);
foreach($_FILESї'filetoupload']ї'name'] as $n => $name)
{
$filedata = array();
foreach($keys as $key)
$filedataї$key] = $_FILESї'filetoupload']ї$key]ї$n];
function processFile($filedata); {
//upload code// }
processFile($_FILESї'filetoupload']ї$key]ї$n]);
}
That's what I was getting at, I was just wondering if
Code: Select all
function processFile($filedata); {
//upload code// }
processFile($_FILESї'filetoupload']ї$key]ї$n]);
that part was correct?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 04, 2005 4:04 pm
nope.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Fri Mar 04, 2005 4:10 pm
well......
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri Mar 04, 2005 4:14 pm
that function doesn't have anything in it and you're just calling it again within the function...
you need to make it do soemthing
research move_uploaded_file