내 사이트는 사용자가 파일을 업로드하고 사용자가 다운로드 할 수 있도록 공개 할 수있게합니다.양식이 제출되면 사용자 이름을 가져 와서 '작성자'아래의 DB에 저장하십시오.
질문 : 데이터베이스에 사용자 이름 추가 (이미 등록되어 데이터베이스에 저장되어 있습니다. 파일 업로드 양식 용입니다.) 양식이 제출되면 제출하십시오. 그들이 양식을 제출했기 때문에 저자 밑으로 가고 싶습니다. 어떻게해야합니까?
어떻게해야합니까? - 양식이 제출되면 사용자의 사용자 이름을 가져 와서 '저자'아래의 데이터베이스에 저장하고 싶습니다.
upload.php :파일 업로드를 제어합니다.
<?php include('dbconnect.php'); ?>
<?php
//check if form is submitted
if (isset($_POST['submit']))
{
$filename = $_FILES['file1']['name'];
//upload file
if($filename != '')
{
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$allowed = ['zip', 'rar', 'php', 'html', 'sql'];
//check if file type is valid
if (in_array($ext, $allowed))
{
// get last record id
$sql = 'select max(id) as id from tbl_files';
$result = mysqli_query($con, $sql);
if (count($result) > 0)
{
$row = mysqli_fetch_array($result);
$filename = ($row['id']+1) . '-' . $filename;
}
else
$filename = '1' . '-' . $filename;
//set target directory
$path = 'uploads/';
$created = @date('Y-m-d H:i:s');
move_uploaded_file($_FILES['file1']['tmp_name'],($path . $filename));
$author= $username;
$title = '';
if(!empty($_POST['title']))
{
$title = mysqli_real_escape_string($con, $_POST['title']);
}
$description = '';
if(!empty($_POST['description']))
{
$description = mysqli_real_escape_string($con, $_POST['description']);
}
// insert file details into database
$sql = "INSERT INTO tbl_files(author, filename, created, title, description) VALUES('$username', '$filename', '$created', '$title', '$description')";
mysqli_query($con, $sql);
header("Location: new-project.html?st=success");
}
else
{
header("Location: new-project.html?st=error");
}
}
else
header("Location: new-project.html");
}
?>
새로운 project.html :파일 업로드 양식. 누구 전에
<?php
include_once('includes/header.php'); ?>
<?php
include_once 'dbconnect.php';
// fetch files
$sql = "select filename from tbl_files";
$result = mysqli_query($con, $sql);
?>
<?php
session_start();
include_once "vendor/autoload.php";
$page = new membership\Page(1);
if ($page->isValid() == true) {
?>
<div id="container">
<div class="wrapper">
<div id="content">
<h2>New Project</h2>
<p><center>
<form action='upload.php' method='post' enctype='multipart/form-data'>
<legend>Select File to Upload:</legend>
<div class='form-group'>
Title: <br /><input type='text' name='title' maxlength="255"/><br /><br />
Description: <br /><textarea type='text' name='description' maxlength="2000"></textarea><br /><br />
<input type='file' name='file1' />
</div>
<div class='form-group'><br />
<input type='submit' name='submit' value="Upload" class='btn btn-info'/>
</div>
<?php if (isset($_GET['st'])) { ?>
<div class='alert alert-danger text-center'>
<?php
if ($_GET['st'] == "success") {
echo "File Uploaded Successfully!";
} else {
echo 'Invalid File Extension!';
}
?>
</div>
</form></center>
</p><?php } ?>
<br /></div>
</p>
<div id="column">
<div class="holder">
<h2>Project Upload Rules</h2>
<ul id="latestnews">
This is this rules you must follow for uploading a project.<br /><br />
- You must own the project/script.<br />
- Must be 100% clean/safe.<br />
- Code must be easy to read.<br />
- No outdated code.<br />
<br />
If you don’t follow the rules your account who be banned.
<br />
</p>
<br /></p>
</li>
</ul>
</div>
</div>
<br class="clear" />
</div>
</div>
<?php } ?>
<?php include_once('includes/footer.php'); ?>
아무것도 그래 난이 .HTML 파일에 PHP를 사용하도록 허용하고 말한다. 어떤 도움이 좋을 것입니다. 감사.
그래서, 작동하지 않는 것은 무엇입니까? 그게 무슨 질문입니까? –
질문 : 양식이 제출되면 데이터베이스에 사용자 이름 추가 (이미 등록되어 데이터베이스에 저장되어 있습니다. 파일 업로드 양식 용입니다). 그들이 양식을 제출했기 때문에 저자 밑으로 가고 싶습니다. 어떻게해야합니까? – Brian
질문이있는 게시물이 업데이트되었습니다. – Brian