0

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.

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.

Noah
  • 1
  • 1
  • What have you tried? This isn't the right place to ask for the solution to a piece of functionality, rather - you should be trying it yourself and asking specific questions when you get stuck. – Hamish Dec 25 '10 at 06:21

1 Answers1

0

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!

cocacola09
  • 650
  • 7
  • 14
  • Thank you for helping. I tried what you told me to put and I am receiving a parse error "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in prod/uploader.php on line 25" Is there anyway we could chat over MSN or another chat client, I would really like to talk to you about fixing this – Noah Dec 25 '10 at 06:50