0
由於此代碼在添加帖子時起作用,因此我感到惱火。但是,當我編輯帖子時,此代碼不想將新的更新圖像上傳到文件夾中。它確實如此,但它是一個「破損」的文件,沒有正確上傳。爲什麼我有這些問題?文件不會上傳到帶有move_uploaded_file()的文件夾中。哪裏不對?
<?php
if (isset($_POST['postupdate'])) {
$editPostTitle = trim($_POST['editposttitle']);
$editPostAuthor = trim($_POST['editpostauthor']);
$editPostStatus = trim($_POST['editpoststatus']);
$editPostTags = trim($_POST['editposttags']);
$post_image = $_FILES['editimage']['name'];
$post_image_temp = $_FILES['editimage']['tmp_name'];
$editPostContent = trim($_POST['editpostcontent']);
move_uploaded_file($post_image_temp, "./images/".$post_image);
print_r(error_get_last());
$updateposts = $conn->prepare("
UPDATE posts
SET post_title = ?, post_author = ?, post_tags = ?, post_image = ?, post_content = ?
WHERE post_id = ?
");
$updateposts->bind_param("sssssi", $editPostTitle, $editPostAuthor, $editPostTags, $editPostImage, $editPostContent, $editId);
$updateposts->execute();
$updateposts->close();
}
這裏就是我遇到的一個例子:
我認爲你必須使用完美的路徑,像下面一樣' move_uploaded_file($ post_image_temp,Yii的::路徑是你的項目/網絡/圖像/ –
檢查輸入文件具有文件路徑($ _FILES ['editimage']) – Gopalakrishnan
我看到幾個錯誤,不知道它是否導致它,但改變它們,在SQL中查詢bindparam你傳遞$ editPostImage這不是你的腳本中的變量,通過$ post_image因爲它的名字 – Exprator