if(move_uploaded_file($_FILES[$thumbnail_fieldname]['tmp_name'], $thumbnail_filename) &&
//move desktop files
move_uploaded_file($_FILES[$desktop_fieldname_1280x800]['tmp_name'], $desktop_filename_1280x800) &&
move_uploaded_file($_FILES[$desktop_fieldname_1366x768]['tmp_name'], $desktop_filename_1366x768) &&
move_uploaded_file($_FILES[$desktop_fieldname_1920x1080]['tmp_name'], $desktop_filename_1920x1080)){
echo "<p>We can move all files.</p>";}
在上面的代码中,当其中一个条件失败时,不会打印文本,这是因为&amp;&amp;这意味着所有需要都是真的,我想在这里实现的是当选择任何文件上传它应该通过条件并打印文本,如果没有选择任何一个或两个文件,它可以跳过并且仍然打印文本,因为一个文件存在,如果没有选择文件,则条件应为false。它不能用||来完成因为如果一个是真的,一切都是真的,那么可以使用什么组合来做到这一点?
例如 拇指移动文件移动= ture
桌面文件1280x800已移动= ture
桌面文件1366x768 未移动 = false //从这里它应该测试下一个条件
桌面文件1920x1080 moving = true
//并且应该打印输出。
答案 0 :(得分:3)
这个怎么样:
// trys to upload the thumbnail
if(move_uploaded_file($_FILES[$thumbnail_fieldname]['tmp_name'], $thumbnail_filename)
// and tries to upload all the other images and store the return values.
// if one or more of them succeeded print the message
&& in_array(TRUE, array(
move_uploaded_file($_FILES[$desktop_fieldname_1280x800]['tmp_name'], $desktop_filename_1280x800),
move_uploaded_file($_FILES[$desktop_fieldname_1366x768]['tmp_name'], $desktop_filename_1366x768),
move_uploaded_file($_FILES[$desktop_fieldname_1920x1080]['tmp_name'],$desktop_filename_1920x1080)
))) {
echo 'upload done';
} else {
echo 'no upload happened';
}