Move_uploaded_file() 函数不起作用 [英] Move_uploaded_file() function is not working

查看:31
本文介绍了Move_uploaded_file() 函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网站,我希望用户能够上传文件.所以我正在努力学习如何做到这一点.我研究了一下,它说我必须使用函数 move_uploaded_file().我编写的代码就像在示例中一样(更改数据),但它不起作用.请帮助我,我是这些新手.这是我到目前为止所做的:

I'm working on a website and I want the user to be able to upload files. So I'm trying to learn how to do that. I researched and it said that I had to use the function move_uploaded_file(). I wrote the code just like it was on the example (changing the data), but it wouldn't work. Please help me, I'm new at these. Here's what I've done so far:

<!DOCTYPE html>
<html>
   <head>
   </head>
<body>
   <form action="upload_file.php" method="POST" enctype="multipart/form-data">
      <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
      <input type="file"name="file">
      <input type="submit">
   </form>
</body>
<html>

这是upload_file.php:

This is the upload_file.php:

<!DOCTYPE html>
<html>
  <head>
  <head>
     <body>
        <?php
          $move = "/Users/George/Desktop/uploads/";
          echo $_FILES["file"]['name']."<br>";
          echo $_FILES["file"]['tmp_name']."<br>";
          echo $_FILES["file"]['size']."<br>";
          echo $_FILES['file']['error']."<br>";
          move_uploaded_file($_FILES['file']['name'], $move);
        ?>
     <body>
<html>

推荐答案

该文件将被存储在一个临时位置,因此使用 tmp_name 而不是 name:>

The file will be stored in a temporary location, so use tmp_name instead of name:

if (move_uploaded_file($_FILES['image']['tmp_name'], __DIR__.'/../../uploads/'. $_FILES["image"]['name'])) {
    echo "Uploaded";
} else {
   echo "File not uploaded";
}

这篇关于Move_uploaded_file() 函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆