0

Hi,

I am reading in a bunch of files to upload but they are in an array:

<input id="tab1file0" class="tab1Files files" type="file" name="tab1file[]" />
<input id="tab1file1" class="tab1Files files" type="file" name="tab1file[]" />

To upload the files I call a function uploadFile() which looks like this:

function uploadFile($thefile) {
		$base_path = "files/";
		$target_path = $base_path . basename( $_FILES[$thefile]['name']);
		echo($_FILES[$thefile]['tmp_name']);
		if(move_uploaded_file($_FILES[$thefile]['tmp_name'], $target_path)) {
			echo "The file ".  basename( $_FILES[$thefile]['name'])." has been uploaded <br>";
		} else{
			echo "There was an error uploading the file".basename( $_FILES[$thefile]['name']).", please try again!<br>";
		}
}

The only problem is when I get the files from the form, they are in an array and I can't seem to point the correct string to the upload file function.

Thanks!

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by network18
0

Hi,

I am reading in a bunch of files to upload but they are in an array:

<input id="tab1file0" class="tab1Files files" type="file" name="tab1file[]" />
<input id="tab1file1" class="tab1Files files" type="file" name="tab1file[]" />

To upload the files I call a function uploadFile() which looks like this:

function uploadFile($thefile) {
		$base_path = "files/";
		$target_path = $base_path . basename( $_FILES[$thefile]['name']);
		echo($_FILES[$thefile]['tmp_name']);
		if(move_uploaded_file($_FILES[$thefile]['tmp_name'], $target_path)) {
			echo "The file ".  basename( $_FILES[$thefile]['name'])." has been uploaded <br>";
		} else{
			echo "There was an error uploading the file".basename( $_FILES[$thefile]['name']).", please try again!<br>";
		}
}

The only problem is when I get the files from the form, they are in an array and I can't seem to point the correct string to the upload file function.

Thanks!

you are looking for method like below -

extract($_POST);

foreach($tab1file as $key=>$value)
{
	//call your function here
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.