I am trying to save files from a file upload which has more than one file using a foreach loop. But the move_uploaded_file is only executing once. I tried printing $file['tmp_name'], but it's printing two array values in one single line as text. How can fix this .. Thanks ..
public function uploadFile($filename)
{
$file_ary = $this->reArrayFiles($_FILES[$filename]);
foreach ($file_ary as $file) {
move_uploaded_file($file['tmp_name'] , '../uploads/' . '.txt');
}
}
function reArrayFiles(&$file_post) {
$file_ary = array();
if(!is_array($file_post['name']))
return array($file_post);
$file_count = count($file_post['name']);
$file_keys = array_keys($file_post);
for ($i=0; $i<$file_count; $i++) {
foreach ($file_keys as $key) {
$file_ary[$i][$key] = $file_post[$key][$i];
}
}
return $file_ary;
}
$file_ary :- Array ( [0] => Array ( [name] => customer care.txt [type] => text/plain [tmp_name] => C:\Program Files (x86)\EasyPHP-DevServer- 14.1VC11\binaries\tmp\php7B21.tmp [error] => 0 [size] => 11 ) [1] => Array ( [name] => ss.txt [type] => text/plain [tmp_name] => C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\binaries\tmp\php7B32.tmp [error] => 0 [size] => 0 ) [2] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) )
$file['tmp_name'] : C:\Program Files (x86)\EasyPHP-DevServer- 14.1VC11\binaries\tmp\phpA38A.tmpC:\Program Files (x86)\EasyPHP-DevServer- 14.1VC11\binaries\tmp\phpA38B.tmp

$file_aryherearray?echo $file['error'];in order to check if an error occurred during the upload. 2)$res = move_uplo..; var_dump($res)to check if an error occurred during the upload. Share with us the output of them both.