Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.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_File Upload_Upload - Fatal编程技术网

Php 如何使人们可以上传文件到我的网站并显示它们?

Php 如何使人们可以上传文件到我的网站并显示它们?,php,html,file-upload,upload,Php,Html,File Upload,Upload,如何使人们能够上传文件到我的网站并显示它们,例如,我希望人们能够上传像archive.org这样的书籍。仅供参考,我不懂PHP。这是我的密码 <html> <head> <title>Book Store</title> <link rel="shortcut icon" href="logo2.ico" /> <link href = "style1.cs

如何使人们能够上传文件到我的网站并显示它们,例如,我希望人们能够上传像archive.org这样的书籍。仅供参考,我不懂PHP。这是我的密码

<html>    
    <head> 

        <title>Book Store</title>  
        <link rel="shortcut icon" href="logo2.ico" />
         <link href = "style1.css" type = "text/css" rel = "stylesheet" />  
    </head>    
    <body> 

    <style>

</style>

</div>


    <h1>Book Store</h1>
     <input type="text" id="booksearch" onkeyup="search()" placeholder="Search for books.."size="40">

<ul id="myUL">
  <li><a href="">A</a></li><br>
  <li><a href="alice.epub">Alice and Wonderland</a></li><br>
  <li><a href="">B</a></li><br>
  <li><a href="Bible kjv pdf.html">Bible King James Version</a></li><br>
  <li><a href="">H</a></li><br>
  <li><a href="hunted down.epub">Hunted Down by Charles Dickens</a></li><br> 
  <li><a href="">P</a></li><br>
  <li><a href="Pilgrim progress.html">Pilgrim Progress</a></li>
  <li><a href="Pride and Prejudice.epub">Pride and Prejudice epub</a></li><br>
  <li><a href="">S</a></li><br>
  <li><a href="Sherlock Holmes complete book.epub">Sherlock Holmes complete book epub</a></li>
  <li><a href="cano.pdf">Sherlock Holmes complete book pdf</a></li><br>
  <li><a href="">T</a></li><br>
  <li><a href="Holmes.pdf" download>The Adventures of Sherlock Holmes pdf</a><br></li>
  <li><a href="fatherbrown1.epub">The Innocence of Father Brown book ep 1 epub</a></li>
  <li><a href="fatherbrown2.epub">The Wisdom of Father Brown book ep 2 epub</a></li>
  <li><a href="fatherbrown3.epub">The Incredulity Of Father Brown book ep 3 epub</a></li>
  <li><a href="fatherbrown4.epub">The Scandal Of Father Brown ep 4 epub</a></li>
  <li><a href="fatherbrown5.epub">The Secret Of Father Brown ep  epub</a></li><br>
  <li><a href="">N</a></li><br>
  <li><a href="nontredam.epub">Nontre Dam history</a></li><br>
  <li><a href="">R</a></li><br>
  <li><a href="romeo.epub">Romeo and Juliet</a></li>
</ul>   
<a href="https://play.google.com/store/apps/details?id=com.faultexception.reader">Get free epub reader for android</a><br>
<script>
function search() {
  // Declare variables
  var input, filter, ul, li, a, i, txtValue;
  input = document.getElementById('booksearch');
  filter = input.value.toUpperCase();
  ul = document.getElementById("myUL");
  li = ul.getElementsByTagName('li');

  // Loop through all list items, and hide those who don't match the search query
  for (i = 0; i < li.length; i++) {
    a = li[i].getElementsByTagName("a")[0];
    txtValue = a.textContent || a.innerText;
    if (txtValue.toUpperCase().indexOf(filter) > -1) {
      li[i].style.display = "";
    } else {
      li[i].style.display = "none";
    }
  }
}
</script>





       <meta http-equiv="Refresh" content="600">    





<button onclick="JavaScript:alert('You will love this book!')">
<img src="http://moziru.com/images/book-clipart-cartoon-14.jpg" alt="What We think of this Book" height = "100">
<br>What We think of this Book</button>
<br>
<a href="html.html" atnip construction>Atnip Construction</a><br>
</body>    
</html>    

书店
书店

















函数搜索(){ //声明变量 var输入、滤波器、ul、li、a、i、TXT值; 输入=document.getElementById('booksearch'); filter=input.value.toUpperCase(); ul=document.getElementById(“myUL”); li=ul.getElementsByTagName('li'); //循环浏览所有列表项,并隐藏与搜索查询不匹配的项 对于(i=0;i-1){ 李[i].style.display=“”; }否则{ li[i].style.display=“无”; } } }
我们怎么看这本书

请告诉我我需要添加到该代码中的内容。我没有任何我想要的版本。如果有任何问题 请问

HTML


请提供下列资料:
主机

用户名

密码

目标目录

文件

php


快速简便的解决方案:

index.html

<!DOCTYPE html>
<html>
    <head>
        <title>Upload test</title>
    </head>
    <body>
        <form action="upload.php" method="post" enctype="multipart/form-data">
            File: <input type="file" name="file"/> 
            <input type="submit" value="Upload" />
        </form>
    </body>
</html>

您希望人们能够将文件上载到您的服务器,还是使用cdn或其他服务器?希望是我的服务器,但如果这非常困难,我可以使用cdn。就像学习任何语言一样,从小处着手。从一个简单的html文档开始,该文档显示一个输入文本框和一个链接到输入文本框的提交按钮。然后为该表单编写一个php脚本,将您输入的任何数据上传到该表单中。然后,您需要练习实现安全性,这样A-Hole就不能上传任何恶意或XSS攻击您的内容。确保通过REG-EX验证所有文本输入,甚至是文件名,并运行一个函数以确保书中只包含文本。上传文件不仅仅是上传文件,还有很多。在互联网上尤其如此。如果你真的打算让公众WWW访问个人服务器,那么安全性是至关重要的,特别是如果你打算保存个人数据。他们只能上传某些文件类型,如Books,比如如何上传。或链接到教程我链接了教程,但没有设置主机、用户名、密码和目录字段(在上载文件的php代码中定义它们)如果遇到任何问题,请在此处询问。我收到错误警告:move_uploaded_file(/usr/local/temp/phpA235.tmp):无法打开流:在第11行的C:\xampp1\htdocs\dashboard\upload.php中没有此类文件或目录警告:move_uploaded_file():无法将第11行C:\xampp1\htdocs\dashboard\upload.php中的“C:\xampp1\tmp\phpA235.tmp”移动到“/usr/local/temp/phpA235.tmp”,无法将上载的文件移动到工作目录。我在用户名和主机等中定义了什么。
<?php
// get FTP access parameters
$host = $_POST['host'];
$user = $_POST['user'];
$pass = $_POST['pass'];
$destDir = $_POST['dir'];
$workDir = "/usr/local/temp"; // define this as per local system
// get temporary file name for the uploaded file
$tmpName = basename($_FILES['file']['tmp_name']);
// copy uploaded file into current directory
move_uploaded_file($_FILES['file']['tmp_name'], $workDir."/".$tmpName) or      die("Cannot move uploaded file to working directory");
// open connection
$conn = ftp_connect($host) or die ("Cannot initiate connection to host");
// send access parameters
ftp_login($conn, $user, $pass) or die("Cannot login");
// perform file upload
$upload = ftp_put($conn, $destDir."/".$_FILES['file']['name'], $workDir."/".$tmpName, FTP_BINARY);
// check upload status
// display message
if (!$upload) {
    echo "Cannot upload";
} else {
    echo "Upload complete";
}
// close the FTP stream
ftp_close($conn);
// delete local copy of uploaded file
unlink($workDir."/".$tmpName) or die("Cannot delete uploaded file from working directory -- manual deletion recommended");
?>
<!DOCTYPE html>
<html>
    <head>
        <title>Upload test</title>
    </head>
    <body>
        <form action="upload.php" method="post" enctype="multipart/form-data">
            File: <input type="file" name="file"/> 
            <input type="submit" value="Upload" />
        </form>
    </body>
</html>
<?php
    if (isset($_FILES['file'])) {
        $file = $_FILES['file'];

        $file_name = $file['name'];
        $file_tmp = $file['tmp_name'];
        $file_size = $file['size'];
        $file_error = $file['error'];

        $file_ext = explode(".", $file_name);
        $file_ext = strtolower(end($file_ext));

        $allowed = array("epub", "pdf", "html"); //The extensions you allow

        if (in_array($file_ext, $allowed)) {
            if ($file_error === 0) {
                if ($file_size <= 2097152) {
                    $file_destination = ' '.$file_name; // If ' ', the file will be placed in this directory
                    if (move_uploaded_file($file_tmp, $file_destination)) {
                        echo $file_destination;
                    } else {
                        echo "An error has been encountered while moving your file!";
                    }
                } else {
                    echo "Your file is too big!";
                }
            } else {
                echo "An error has been encountered while uploading your file!";
            } 
        } else {
            echo "You can't upload files of this type!";
        }
    }
?>
<?php
    if (isset($_FILES['file'])) {
        $host = "ftp.example.com";
        $user = "username";
        $pass = "password";
        $destDir = "/public_html";    //The destination directory for the uploaded file (`/public_html` is the root directory for your website files, in some cases it could also be `/var/www`)
        $workDir = " ";

        $tmpName = basename($_FILES['file']['tmp_name']);
        move_uploaded_file($_FILES['file']['tmp_name'], $workDir.$tmpName) or die("Cannot move uploaded file to working directory");

        $conn = ftp_connect($host) or die ("Cannot initiate connection to host");
        ftp_login($conn, $user, $pass) or die("Cannot login");
        $upload = ftp_put($conn, $destDir."/".$_FILES['file']['name'], $workDir.$tmpName, FTP_BINARY);
        if (!$upload) {
            echo "Cannot upload\n";
        } else {
            echo "Upload complete\n";
        }
        ftp_close($conn);

        unlink($workDir.$tmpName) or die("Cannot delete uploaded file from working directory -- manual deletion recommended");
    }
?>