$fileType_array = array(IMAGETYPE_JPEG, IMAGETYPE_PNG);
$filenames = array($thumbnail_fieldname, $desktop_fieldname_1280x800, $desktop_fieldname_1366x768, $desktop_fieldname_1920x1080);
$files = array();
foreach($filenames as $filename){
if(isset($_FILES[$filename]['tmp_name'])){
$resource = getimagesize($_FILES[$filename]['tmp_name']);
$type = $resource[2];
if(in_array($type, $fileType_array, TRUE)){
echo "<p>Following files are images:";
array_push($files, $filename);
//$files[$filename] = $filename . "<br />";
}
}
这段代码给了我图像文件,我想做的是将这些图像移动到适当的文件夹..例如对于文件的缩略图thumbnail.png
,我想将此文件移动到文件夹images/thumbnails/thumbnail.png
..我该怎么做? 我认为move_uploaded_file
但不确定如何,因为如果特定文件不是图像,则将其保留并移至下一个..例如,下一个desktop1280x800
文件不是图像,因此它将跳过并移至下一个桌面文件如果它是图像,则将其移动到目录..所以我无法按顺序完成我猜..下面是移动这些文件的代码我只想移动特定的而不是全部
if(move_uploaded_file($_FILES[$thumbnail_fieldname]['tmp_name'], $thumbnail_filename)
//move desktop files
&& 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)))){
//Files moved.
}