View Full Version : File editing and uploading?

03-28-2004, 03:39 PM
Hi guys,

I'm very unsure on how to go about achieving this.
I'd like to have a page where a user is able to:
1. Upload a file (.doc file, .txt file, images) and preferrably store these files somewhere in a sub-folder (all are done through a web interface, not ftp).
2. Post texts - Just one big piece of text, and the ability to edit it themself. So its like one big textbox.

I'm open to any solutions.

Thank you in advance for any help. =).

03-29-2004, 04:11 PM
Ok so if i understand you correctly you are after a form that a user can browse their files and then upload one with the correct file extension?

ok well i have recently built a site for a customer that required them to keep the stocklist up to date, so i put this together. If you see anything wrong with it then please let me know.

1. Create a form like the following

<form action="upload.php" method="post" ENCTYPE="multipart/form-data">
<input type="file" name="file2" size="30">
<input name="submit2" type="submit" value="Update">

2. Create a php page called upload.php or similar and add the following code

// ==============
// Configuration
// ==============
$uploaddir = "files"; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777!
$allowed_ext = "doc, txt, xls"; // These are the allowed extensions of the files that are uploaded
$max_size = "50000"; // 50000 is the same as 50kb - depends on what you are uploading
$max_height = ""; // This is in pixels - Leave this field empty if you don't want to upload images
$max_width = ""; // This is in pixels - Leave this field empty if you don't want to upload images

// Check Entension
$extension = pathinfo($_FILES['file']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";

// Check File Size
if ($ok == "1") {
if($_FILES['file']['size'] > $max_size)
header("Location: http://www.yoursite.com.au/?page=error_upload");

// Check Height & Width
if ($max_width && $max_height) {
list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height)
header("Location: Location: http://www.yoursite.com.au/?page=error_upload");

// The Upload Part
header("Location: http://www.yoursite.com.au/?page=upload_success");
} else {
header("Location: http://www.yoursite.com.au/?page=error_upload");

3. You can now create the error and success pages to let them know of it worked or not.

4. from experiences so far it overwrites the older file. If people think different then please tell me.

5. Please note that you should ensure that this is fairly secure (login before hand or soemthing) and i wouldnt allow upload of exe files ect