【发布时间】:2017-12-08 11:45:49
【问题描述】:
我有这个文件更新代码,我需要将文件路径放在响应数组中。但我的数组是空的:
$response = array();
if (file_exists($directorSerie)) {
if(is_array($_FILES)) {
foreach ($_FILES['fileToUpload']['name'] as $name => $value){
if(is_uploaded_file($_FILES['fileToUpload']['tmp_name'][$name])) {
$sourcePath = $_FILES['fileToUpload']['tmp_name'][$name];
$targetPath = $directorSerieString.$_FILES['fileToUpload']['name'][$name];
array_push($response, $targetPath);
if(move_uploaded_file($sourcePath,$targetPath)) {
$success = "success";
}
}
}
}
}
exit(json_encode($response));
【问题讨论】:
-
您是否在每个
if和foreach块的顶部放置了一条日志记录语句以确保它被输入?您是否尝试过记录$targetPath以查看是否符合您的预期? -
更简单(更常见)'array_push' 语法:$response[] = $targetPath;
-
使用 $response[] = $targetPath;只需给出相同的结果:空数组
-
你能详细说明一下“日志记录”的事情吗?
标签: php foreach array-push