繁体   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