PHP上传照片在两个以上的方向

wztqucjr  于 2023-05-27  发布在  PHP
关注(0)|答案(1)|浏览(251)

我想上传的照片被添加到3个文件夹。代码是正确的,但照片只添加到“上传”文件夹。我检查了文件夹权限和PHP版本;什么都没用。

if($category == "Ogłoszenia"){
    $file_image = time() . "_" . $_FILES['image']['name'];
    $tmp = $_FILES['image']['tmp_name'];
    move_uploaded_file($tmp, "uploaded/".$file_image);  
    copy($_FILES['image']['tmp_name'], "../../../subdomena/bip/files/pl/".$file_image);
    copy(resize_image($_FILES['image']['tmp_name'], 150, 150), "../../../subdomena/bip/files/pl/".$file_image);
} else {
    $file_image = time() . "_" . $_FILES['image']['name'];
    $tmp = $_FILES['image']['tmp_name'];
    move_uploaded_file($tmp, "uploaded/".$file_image);  
}
sczxawaw

sczxawaw1#

您的第二个和第三个副本具有完全相同的文件名。我在第三个副本的末尾添加了“3”来解决这个问题

//1st copy
$file_image = time() . "_" . $_FILES['image']['name'];
$tmp = $_FILES['image']['tmp_name'];
$location = "uploaded/".$file_image;
move_uploaded_file($tmp, $location);
if($category == "Ogłoszenia"){
    //2nd copy
    copy($location, "../../../subdomena/bip/files/pl/".$file_image);
    //3rd copy
    copy($location, "../../../subdomena/bip/files/pl/".$file_image."3");
    resize_image("../../../subdomena/bip/files/pl/".$file_image."3", 150, 150);
}

相关问题