簡體   English   中英

PHP move_uploaded_file未上傳

[英]PHP move_uploaded_file not uploading

我正在嘗試在博客上上傳圖片,但沒有這樣做。 沒有錯誤訊息,只是不上傳。 檢查了文件夾的權限,當我將圖像放置在圖像文件夾中時,它們起作用了,但是添加帖子時卻不起作用。 下面是即時通訊使用的代碼。

任何幫助是極大的贊賞。

$post_image = $_FILES['image']['name'];
$post_image_temp = $_FILES['image']['tmp_name'];

$post_content = mysqli_real_escape_string($connection, $_POST['post_content']);
$post_tags = mysqli_real_escape_string($connection, $_POST['post_tags']);
$post_status = mysqli_real_escape_string($connection, $_POST['post_status']);

// $post_comment_count = 4; //THIS NEEDS TO BE DYNAMIC

move_uploaded_file($post_image_temp,"../images/".$post_image) ;
// if(!move_uploaded_file($post_image_temp,"../images/".$post_image)){
//   echo 'Moved successfully:';
// }else{
//   print_r(error_get_last());
// }

$query = "INSERT INTO posts(post_category_id, post_title, post_author, post_date, post_image, post_content, post_tags, post_status)";
$query .= "VALUES ({$post_category_id},'{$post_title}','{$post_author}',now(),'{$post_image}','{$post_content}','{$post_tags}','{$post_status}') ";

      $create_post_query = mysqli_query($connection, $query);
      confirm($create_post_query);

}

更換

move_uploaded_file($post_image_temp,"../images/".$post_image) ;

move_uploaded_file(
    $post_image_temp,
    __DIR__ . "/../images/" . $post_image
);

改變這些

move_uploaded_file("$post_image_temp,","../images/" . $post_image) ;
if(!move_uploaded_file($post_image_temp,"../images/".$post_image)){

對這些

move_uploaded_file("$post_image_temp,", "images/" . $post_image) ;
if(move_uploaded_file($post_image_temp, "images/" . $post_image)){

經過測試,現在可以正常工作!

您可以使用以下代碼訪問圖像文件夾

move_uploaded_file($post_image_temp,dirname(__FILE__)."/images/".$post_image) ;

但您應確保images文件夾與php文件位於同一文件夾中。 如果images文件夾位於比php文件更高的目錄中,請使用

dirname(__FILE__)."../images/" 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM