試圖讓用戶將圖像上傳到文件夾並查看它但它不會 工作。我有辦法讓人們可以上傳他們的個人資料照片,但不會讓他們上傳到那裏畫廊。以下是它的代碼。我得到的錯誤是,該文件將不會創建一個文件並上傳圖片到該文件夾是這樣的...用戶/羅比/我/ 94399549904fkfkmkd.png無法將圖像上傳到文件夾
if (isset($_FILES["photo"]["name"]) && isset($_POST["gallery"])){
$sql = "SELECT COUNT(id) FROM photos WHERE user='$log_username'";
$query = mysqli_query($db_conx, $sql);
$row = mysqli_fetch_row($query);
if($row[0] > 14){
header("location: ../message.php?msg=The demo system allows only 15 pictures total");
exit();
}
$gallery = $_POST["gallery"];
$target_dir = "/user/$log_username/$gallery/";
$target_file = $target_dir . basename($_FILES["photo"]["name"]);
if (move_uploaded_file($_FILES["photo"]["tmp_name"], $target_file)) {
echo "The file ". basename($_FILES["photo"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
這是形式用戶
$photo_form = '<form id="photo_form" enctype="multipart/form-data" method="post" action="photo_system.php?gallery=yes">';
$photo_form .= '<h3>Hi '.$u.', add a new photo into one of your galleries</h3>';
$photo_form .= '<b>Choose Gallery:</b> ';
$photo_form .= '<select name="gallery" required>';
$photo_form .= '<option value=""></option>';
$photo_form .= '<option value="Myself">Myself</option>';
$photo_form .= '<option value="Family">Family</option>';
$photo_form .= '<option value="Pets">Pets</option>';
$photo_form .= '<option value="Friends">Friends</option>';
$photo_form .= '<option value="Random">Random</option>';
$photo_form .= '</select>';
$photo_form .= ' <b>Choose Photo:</b> ';
$photo_form .= '<input type="file" name="photo" required>';
$photo_form .= '<p><input type="submit" value="Upload Photo Now"></p>';
$photo_form .= '</form>';
你會得到什麼樣的錯誤,這是什麼形式?太多未知數。 –
順便說一句,你可能在這裏之前輸出標題,你的邏輯關閉。 –
我得到的錯誤是該文件不會創建文件並將圖像上傳到該文件夾,就像這樣...用戶/ robbie /我/ 94399549904fkfkmkd.png –