在多文件夹php上上载图像
我需要上传到两个不同的文件夹图像 这是我的密码 在第一个文件夹上,它正在移动 但在第二个文件夹上,它会生成无法移动第二个文件的异常在多文件夹php上上载图像,php,file-upload,image-upload,Php,File Upload,Image Upload,我需要上传到两个不同的文件夹图像 这是我的密码 在第一个文件夹上,它正在移动 但在第二个文件夹上,它会生成无法移动第二个文件的异常 $target_path = "uploads/"; $target_path = $target_path . basename($_FILES['image']['name']); $target_path1 = "thumbnails/"; $target_path1 = $target_path1 . basename($_FILES['image'][
$target_path = "uploads/";
$target_path = $target_path . basename($_FILES['image']['name']);
$target_path1 = "thumbnails/";
$target_path1 = $target_path1 . basename($_FILES['image']['name']);
try {
//throw exception if can't move the file
if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
throw new Exception('Could not move file');
}
if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_path1))
{
throw new Exception('Could not move 2nd file');
}
一旦您上传,它将删除临时文件($\u文件['image']['tmp\u name']
)。你必须从第一次上传时复制该文件
$success=true;
if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
throw new Exception('Could not move file');
$success=false;
}
if($success) {
if (!move_uploaded_file($target_path, $target_path1))
{
throw new Exception('Could not move 2nd file');
}
}
上载到第二个文件夹
if (!move_uploaded_file($target_path, $target_path1)){
throw new Exception('Could not move 2nd file');
}
move\u upload\u file()
已将文件移动到您的$target\u路径
路径。因此,您的temp
中没有任何内容,这是您第二次使用copy()
。命令将其上载
if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
throw new Exception('Could not move file');
}
if(!copy ( $target_path , $target_path1 ))
{
throw new Exception('Could not move 2nd file');
}