1 回答

TA貢獻1818條經驗 獲得超8個贊
首先,讓我們看看你做錯了什么:
// You're moving the original file right here, this is fine
if(move_uploaded_file($source_path, $target_path)) {
$db->insert("images", $array);
}
// This won't work, because you're trying to access orginal file (moved already)
image::resize($source_path, "img/clients/thumbs/".$targetFile, 100, 100);
$db->insert("log", array("action" => "image", "inserted_on" => date("Y-m-d
H:i:s"), "users_id" => $_POST["users_id"], "clients_id" => $id));
// Now you're trying to move again the original file
if(move_uploaded_file($source_path, $target_path1)) {
echo "Success";
}
然后,邏輯更簡單:
首先:如果有文件,請將其移動到目標位置,并保留該文件,無需修改
第二:創建拇指并將其保存在其相應的文件夾中,您無需復制,因為文件已經存在
if(!empty($_FILES)) {
$fileName = $_FILES['file']['name'];
$source_path = $_FILES['file']['tmp_name'];
$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
$targetFile = $id."_".$fileName;
$target_path = "img/clients/".$targetFile;
$array["filename"] = $targetFile;
$array["main"] = (int)($db->query("SELECT * FROM images WHERE clients_id = :clients_id;", array("clients_id" => $id), false) == 0);;
$array["clients_id"] = $id;
// Move original file
if(move_uploaded_file($source_path, $target_path)) {
$db->insert("images", $array);
// Create thumb only if the file was moved, otherwhise you'll get errors
// Your source is the file moved, not the one on temp folder
image::resize($target_path, "img/clients/thumbs/".$targetFile, 100, 100);
$db->insert("log", array("action" => "image", "inserted_on" => date("Y-m-d
H:i:s"), "users_id" => $_POST["users_id"], "clients_id" => $id));
}
}
- 1 回答
- 0 關注
- 81 瀏覽
添加回答
舉報