【问题标题】:How to specify path for the folder in Windows如何在 Windows 中指定文件夹的路径
【发布时间】:2015-03-16 20:41:56
【问题描述】:

我有一个表单可以让用户将文件上传到服务器,但我不知道如何在服务器中为要存储文件的文件夹编写正确的路径,以及如何获取稍后下载特定文件的路径。

服务器中的路径:

/public_html/upload_files

我得到的错误:

警告:move_uploaded_file(upload_files/project_guidelines.pdf): 无法打开流:中没有这样的文件或目录 D:\sites\dwts.com\public_html\website\creat.php 第 50 行警告: move_uploaded_file():无法将“C:\Windows\Temp\php14AC.tmp”移动到 'upload_files/project_guidelines.pdf' 在 D:\sites\dwts.com\public_html\website\creat.php 第 50 行错误 上传文件

代码:

$len = count($_FILES['Attachment']['name']);

for($i = 0; $i < $len; $i++) {

$uploadDir = 'upload_files/';

$fileName = $_FILES['Attachment']['name'][$i];
$tmpName = $_FILES['Attachment']['tmp_name'][$i];
$fileSize = $_FILES['Attachment']['size'][$i];
$fileType = $_FILES['Attachment']['type'][$i];

$filePath = $uploadDir . basename($_FILES['Attachment']['name'][$i]);

$result = move_uploaded_file($tmpName,$filePath);
if (!$result) {
    echo "Error uploading file";
    exit;
}

【问题讨论】:

  • 错误似乎很清楚 - 有什么问题?
  • 我不知道正确的目录或语法是什么,我应该写下服务器的用户名吗? (我该怎么办):/

标签: php path


【解决方案1】:
$uploadDir = 'upload_files/';

驱动器在哪里?它的 Windows,所以它需要一个驱动器:

$uploadDir = 'c:/upload_files/';

您不能为move_uploaded_file 的第二个参数提供部分位置...它需要完整路径。

【讨论】:

  • 上传到服务器了吗?
  • 非常感谢 :) 我不知道我应该写驱动器 D:\sites\username\public_html\ 它现在可以工作了..
猜你喜欢
  • 1970-01-01
  • 2020-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多