开发者

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 开发者_如何学JAVAto 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.

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'.

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. 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

<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

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

   // 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.

Hope this help!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜