[英]move_uploaded_file not moving file to folder
I have a form from which I can upload some files. 我有一个可以上传一些文件的表格。 The file array shows up correct when I print
it but there is no file in the destination folder. 当我print
文件阵列时显示正确,但是目标文件夹中没有文件。 What am I missing? 我想念什么?
This is my code: 这是我的代码:
// Fileupload
if (!is_dir('../incidentbijlagen/'.$inc['incident']['companyname'].'')) {
mkdir('../incidentbijlagen/'.$inc['incident']['companyname'].'', 0777, true);
}
$uploads_dir = '../incidentbijlagen/'.$inc['incident']['companyname'].'/';
foreach($bijlage['incident'] as $key => $file){
$tmp_name = $file['incident']['tmp_name']['bijlage'][$key];
$name = basename($file['incident']['name']['bijlage'][$key]);
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
There are no errors in my error_log so I am not sure why the file is not moved. 我的error_log中没有错误,所以我不确定为什么不移动文件。 This is what my array looks like when I print
it: 这是我print
数组时的样子:
Array
(
[incident] => Array
(
[name] => Array
(
[bijlage] => Array
(
[0] => fblogosnm.jpg
)
)
[type] => Array
(
[bijlage] => Array
(
[0] => image/jpeg
)
)
[tmp_name] => Array
(
[bijlage] => Array
(
[0] => /tmp/phpnh5aHW
)
)
[error] => Array
(
[bijlage] => Array
(
[0] => 0
)
)
[size] => Array
(
[bijlage] => Array
(
[0] => 20573
)
)
)
)
Get rid of the loop and just try using 0 like this: 摆脱循环,然后尝试使用0像这样:
$tmp_name = $file['incident']['tmp_name']['bijlage'][0];
$name = basename($file['incident']['name']['bijlage'][0]);
move_uploaded_file($tmp_name, "$uploads_dir/$name");
UPDATE 更新
OK for multiple, try this: 确定多个,请尝试以下操作:
foreach($bijlage['incident']['name']['bijlage'] as $key => $file) {
$tmp_name = $file['incident']['tmp_name']['bijlage'][$key];
move_uploaded_file($tmp_name, "$uploads_dir/$file");
}
Try to replace: $uploads_dir = '../incidentbijlagen/'.$inc['incident']['companyname'].'/';
尝试替换: $uploads_dir = '../incidentbijlagen/'.$inc['incident']['companyname'].'/';
with: $uploads_dir = realpath('../incidentbijlagen/'.$inc['incident']['companyname'].'/');
其中: $uploads_dir = realpath('../incidentbijlagen/'.$inc['incident']['companyname'].'/');
This returns the full path (eg: /var/www/yourwebsite/incidentbijlagen/ etc) 这将返回完整路径(例如:/ var / www / yourwebsite / incidentbijlagen /等)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.