PHP上传输入数组并如何查找有多少个文件?
我有这样的表格:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="file" name="photo[]" />
<input type="file" name="photo[]" />
</form>
我用这种方式上传文件:
function upFiles($files){
for($i = 0 ; $i < $files ; $i++){
$FV_filename = $_FILES['photo']['name'][$i];
$fileTYPE = substr($FV_filename , -4);
move_uploaded_file($_FILES['photo']['tmp_name'][$i], uniqid().$fileTYPE);
}
}
upFiles($_POST['howManyFiles']);
正如你所看到的,我从客户端获取了已发送的文件数量。 我想做的是在服务器端检查已收到多少文件。 我怎样才能做到这一点?是否有任何内置的 php 函数,如果没有那么如何创建一个?
I have this form :
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="file" name="photo[]" />
<input type="file" name="photo[]" />
</form>
And I upload the files with php this way :
function upFiles($files){
for($i = 0 ; $i < $files ; $i++){
$FV_filename = $_FILES['photo']['name'][$i];
$fileTYPE = substr($FV_filename , -4);
move_uploaded_file($_FILES['photo']['tmp_name'][$i], uniqid().$fileTYPE);
}
}
upFiles($_POST['howManyFiles']);
As you can see I get from the the client side how many files have been sent.
What I want to do is to check in the server side how many files have been received.
How can I do that? Is there any built in php function, if not then how to create one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应该有效。或者,只需将
for
循环重写为foreach
:should work. Alternatively, just rewrite your
for
loop to aforeach
:您可以使用
is_uploaded_file
检查文件是否已上传,如下所示:您可以使用
foreach
循环遍历所有上传的照片,而不是使用幻数< /em>.来自: php.net
You could check whether the file has been uploaded with
is_uploaded_file
, like so:You could use
foreach
to loop over all the uploaded photos instead of using a magic number.From: php.net
迭代 $_FILES 数组:
Iterate over the $_FILES array: