そのため、ダウンロード可能な書籍を含むWebページがあり、書籍をサーバーにアップロードするオプションを追加しましたが、ファイルをアップロードするときにメインページに表示するようにしたいのです。これが私のコードです。
アップロードしたファイルを表示したいメインページ
<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 5 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>
<a href="archive.html" atnip construction>Upload a Book</a><br>
<a href="store.html" atnip construction>sign up</a><br>
</body>
</html>
upload.phpという名前のPHPコードをアップロードします
<?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", "mp4"); //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!";
}
}
?>
そして、それが重要な場合、私は000webhostingを使用しています。さらに情報が必要な場合は事前に感謝します。
データベースまたはファイルのいずれかを使用できます。これらの答えは両方とも、データをどこかに書き込んでから取得し、Webページに表示する必要があります。
ファイルソリューションが必要なので、以下のコードでうまくいきます。
アップロードページのHTML:
<!DOCTYPE html>
<html>
<head>
<title>Upload test</title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Name: <input type="text" name="name" required/>
File: <input type="file" name="file" required/>
<input type="submit" value="Upload" />
</form>
</body>
</html>
アップロードページのPHP:
<?php
if (isset($_FILES['file']) && isset($_POST['name'])) {
$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", "mp4"); //The extensions you allow
if (in_array($file_ext, $allowed)) {
if ($file_error === 0) {
if ($file_size <= 2097152) { //the maximum filesize
$file_destination = ''.$file_name; // If ' ', the file will be placed in this directory
if (move_uploaded_file($file_tmp, $file_destination)) {
echo $file_destination;
$fp = fopen('book_list.txt', "a");
fwrite($fp, $_POST['name']. "|||" .$file_destination."\n");
fclose($fp);
} 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スクリプトでこのようなもの:
<?php
$content = file('book_list.txt', FILE_IGNORE_NEW_LINES);
foreach ($content as $cont) {
$names = explode("|||", $cont);
echo "<li><a href='example.com/path_to_upload.php/".$names[1]."'>".$names[0]."</a></li>"; //if upload.php is in the root directory of your website, remove "path_to_upload.php/"
}
?>
タグ.php
内にコードを含めることができるように、メインページをファイルに変換する必要があります<ul>
。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加