简体   繁体   English

帮助PHP上传和文件管理器脚本

[英]Help with a PHP upload and file manager script

I am trying to create a script that has a basic file upload button and a form function. 我正在尝试创建一个具有基本文件上传按钮和表单功能的脚本。 I am also trying to make a script that would be a file manager with all the input data from the form. 我还试图制作一个脚本,该脚本将成为文件管理器,其中包含来自表单的所有输入数据。

Form Layout: 表格布局:

Browse (Button) ----> When clicked prompts the user to upload only pdf files. 浏览(按钮)---->单击时,提示用户仅上载pdf文件。

File Name (Form): ----> The user must put a file name 文件名(表格):---->用户必须输入文件名

Brief Description (Form): ----> The user must put a brief description of their file 简短说明(表格):---->用户必须对文件进行简短说明

Upload (Button): ----> Once this button is hit the file is uploaded to my web server to a folder called 'files'. 上载(按钮):---->按下此按钮后,文件即被上传到我的Web服务器上名为“文件”的文件夹。

File Browser Layout: 文件浏览器布局:

The file browser would be a table that would display all the files uploaded using the previous form. 文件浏览器将是一个表,该表将显示使用先前表单上载的所有文件。 Each column in the table would show the size of the file, and show the information the uploader posted in 'File Name' and 'Brief Description' 表格中的每一列都会显示文件的大小,并显示上传者在“文件名”和“简要说明”中发布的信息

My guess is I would need some sort of SQL database that the form information would be stored. 我的猜测是,我需要某种SQL数据库来存储表单信息。 Then I would need to make a file browser that displayed the stored information. 然后,我需要制作一个显示所存储信息的文件浏览器。 I am not sure how to go about this task. 我不确定如何执行此任务。 I would really appreciate your help or ideas. 非常感谢您的帮助或想法。 Thank you for your time. 感谢您的时间。

I've just wrote this without checking the errors.... here goes... 我只是写了这个,没有检查错误...。

1) Create the form in upload.php 1)在upload.php中创建表单

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
description <textarea name="description" cols="15" rows="15"></textarea><br>
<input type="submit" value="Upload File" />
</form>

2) create mysql table 2)创建mysql表

CREATE TABLE  `uploads` (
 `ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
 `filename` TEXT NOT NULL ,
 `description` TEXT NOT NULL
) ENGINE = INNODB; 

3) create uploader.php and put your credentials in mysql to match the user / pass of mysql 3)创建uploader.php并将您的凭据放在mysql中,以匹配mysql的用户/密码

   // Where the file is going to be placed 
    $target_path = "uploads/"; 

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

 // Make a MySQL Connection
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("uplodas") or die(mysql_error());

// Insert a row of information into the table "example"
mysql_query("INSERT INTO uplods 
(ID, filename, description) VALUES("","'.$_FILES['uploadedfile']['name'].'", "'.mysql_real_escape_string($_POST['description']).'" ) ") 
or die(mysql_error());  


echo "File Uploaded!";

This will allow you to have a working upload script. 这将使您拥有有效的上传脚本。

a simple file manager will be 一个简单的文件管理器将是

    // Make a MySQL Connection
    mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
    mysql_select_db("uplodas") or die(mysql_error());

// Make a MySQL Connection
$query = "SELECT * FROM uploads"; 

$result = mysql_query($query) or die(mysql_error());


$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['filename']. " - ". $row['description'] ." - DELETE | EDIT";
?>

use UPDATE and DELETE mysql queries to create your delete and edit buttons. 使用UPDATE和DELETE mysql查询创建删除和编辑按钮。

Hope this help! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM