Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用php脚本上载_Php_Html - Fatal编程技术网

无法使用php脚本上载

无法使用php脚本上载,php,html,Php,Html,我有一个php脚本,用于将文件上载到服务器。它先起作用了,但我不知道为什么它又不起作用了。它没有显示任何错误,但该文件仍没有上载到我指定用来保存所有上载文件的目录。以下是负责上传的部分: <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Uploaded: " . basenam

我有一个php脚本,用于将文件上载到服务器。它先起作用了,但我不知道为什么它又不起作用了。它没有显示任何错误,但该文件仍没有上载到我指定用来保存所有上载文件的目录。以下是负责上传的部分:

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
   {

  echo "Uploaded: " . basename($_FILES["file"]["name"]) . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  //by default the size of the file is in bytes so u need to divide by 1024 in order to bring it to KB
  echo "Temporarily stored in: " . $_FILES["file"]["tmp_name"] . "<br />";
  $target="/file/" . basename($_FILES["file"]["name"]) . "<br />";


  }

  if(move_uploaded_file($_FILES["file"]["tmp_name"], $target))
  {
  echo "<h2>" . "The file has been stored on the server" . "<br />" . "<h2 />";
  echo "New storage location is : " . '<a href="/public/files/" >' . $target . '</a>';
  ?>
   <html>
<body>
<div align="right"><a href="/public/files/" >Uploaded files</a></div>
<br />
</body>
</html>
<?php
}
  else
  {
    echo "<h2>" . "Error while saving the file to the server." . "<br />" . "File wont be found in the uploaded files directory" . "<br />" . "<h2 />";
    echo "The error says: " . $_FILE["file"]["error"] . " What do we do now?" ;
    echo"<pre>".print_r($_FILES,true)."</pre>";
    ?>

<?
/file/是服务器文件系统根目录中的一个目录,它几乎肯定不存在。move_上传的_文件在文件系统级别工作,并且完全不知道站点的URI结构。您可能想要更像:


这样文件就会被移动到站点根目录的/file子目录中。

那么它是否会回显其他目录中的任何内容{表单是什么样子的?
move_uploaded_file(...,. $_SERVER['DOCUMENT_ROOT'] . '/file/');
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^---- add this