简体   繁体   English

PHP上传文件未显示在服务器上

[英]PHP Upload file not showing on server

I am writing a PHP to upload .PDF's to my server. 我正在编写一个PHP,以将.PDF上传到我的服务器。 Currently When I "upload" the file the system acts as if the task was completed, yet the file does not show up in the designated folder. 当前,当我“上载”文件时,系统就像任务已完成一样工作,但该文件未显示在指定的文件夹中。

Form Code 表格代码

<form id="add" action="action.php" method="post" enctype="multipart/form-data">
    <table><tr><td>
         <input type="file" name="uploadedfile" id="uploadedfile" required />
    </td></tr><tr><td>
         <input id="upload" type="submit" value="Upload">
    </td></tr></tr></table></form>

PHP Code PHP代码

move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],"Flyers/".$_FILES["uploadedfile"]["name"]);

I think the problem might be that you're trying to write to the folder that the script is running in but you need to give it a full path.. 我认为问题可能是您正在尝试写入脚本在其中运行的文件夹,但是您需要给它一个完整的路径。

Try: move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],"/Flyers/".$_FILES["uploadedfile"]["name"]); 试试:move_uploaded_file($ _ FILES [“ uploadedfile”] [“ tmp_name”],“ / Flyers /".$_ FILES [” uploadedfile“] [” name“]);

with a / before the Flyers and make sure there is a Flyers directory in the root of the server eg. 在Flyers前面加上/,并确保在服务器的根目录中有一个Flyers目录,例如。 public_html/Flyers public_html /传单

and that it is writeable. 并且它是可写的。 (Your ftp client should give you some way of checking the permissions on a folder.) (您的ftp客户端应为您提供一些检查文件夹权限的方法。)

First of all, it is always a good idea to use absolute paths instead of relative paths as you may "get lost" with all the different files you may be using. 首先,使用绝对路径而不是相对路径始终是一个好主意,因为您可能会丢失所使用的所有不同文件。

move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], __DIR__ . "/Flyers/".$_FILES["uploadedfile"]["name"]);

__DIR__ is the directory the script that contains this code resides in, change it accordingly __DIR__是包含此代码的脚本所在的目录,请相应地对其进行更改

Secondly, you should check the return of move_uploaded_file to see if it was successful. 其次,您应该检查move_uploaded_file的返回是否成功。 This function returns a boolean , so if it was true then you know it was successful, otherwise somethine went wrong. 该函数返回一个boolean ,因此,如果它为true则说明它是成功的,否则将出错。

Usually it is folder permissions. 通常是文件夹权限。 If your webserver was not configured properly there maybe permission issues where the user that is running PHP does not have proper permissions to the folder and may be denied permission to write to that folder, which will break move_uploaded_file . 如果您的网络服务器配置不正确,则可能存在权限问题,正在运行PHP的用户对该文件夹没有适当的权限,并且可能被拒绝写入该文件夹的权限,这将破坏move_uploaded_file

To solve this, you will need to fix your server config... which I will not cover here as there are too many variables that will affect this. 要解决此问题,您将需要修复服务器配置...在此不做介绍,因为有太多变量会影响此配置。 But you can try to set 777 or 775 permission to the folder you wish to upload to, either with your ftp software, ssh, or within php with chmod or umask (search them on PHP docs to see how to use) 但是您可以尝试使用ftp软件,ssh或使用chmodumask在php内将希望上传到该文件夹​​的权限设置为777或775(在PHP文档中搜索以了解如何使用)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM