Jump to content

[SOLVED] uploading files in an array HELP!!!!


zhahaman2001

Recommended Posts

I can not get files to upload in and array!! how do i do it? Heres what i got can anyone get this code to work?

 

<?php 
$files_to_upload = 3;
if($step == 2){
for ($i = 1; $i < ($files_to_upload + 1); ++$i) {
	$file_name = $_FILES['file[$i]']['name'];
	$upload_dir = "uploads/$file_name";
	if(move_uploaded_file($_FILES['file[$i]']['tmp_name'], $upload_dir)) {
		print "Upload Successfull!";
	}else{
		print "Error and its all your fault!";
	}
}
}
print "<form method='post' enctype='multipart/form-data' name='frm' action='test.php?step=2'>";
for ($i = 1; $i < ($files_to_upload + 1); ++$i) {
print "<input type='file' name='file[$i]'><br>";
}
print "<input type='submit' value='Upload'>";
print "</form>";
?>

Link to comment
https://forums.phpfreaks.com/topic/51688-solved-uploading-files-in-an-array-help/
Share on other sites

Thanks google  ;D

 

<?php 
$files_to_upload = 3;
if($step == 2){
for ($i = 1; $i < ($files_to_upload + 1); ++$i) { 
	$tmp_name = $_FILES["file"]["tmp_name"][$i]; 
	$name = $_FILES["file"]["name"][$i];  
	$upload_dir = "uploads/$name";
	if(move_uploaded_file($tmp_name,$upload_dir)) {
		print "Upload Successfull!";
	}else{
		print "Error and its all your fault!";
	}
}
}
print "<form method='post' enctype='multipart/form-data' name='frm' action='test.php?step=2'>";
for ($i = 1; $i < ($files_to_upload + 1); ++$i) {
print "<input type='file' name='file[$i]'><br>";
}
print "<input type='submit' value='Upload'>";
print "</form>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.