Log in

View Full Version : .php upload form...



CCJared
02-23-2009, 10:14 PM
Heya,

I'm new here and I was wondering if anyone would be able to help me. I'm quite new to using .php and have done some pretty neat modifications to the forums on my website which run phpBB 3.0.4.

I was wondering if it is possible to create an upload form on a seperate page that allows a user the specify a name for the file he/she wants to upload and then also upload it, and then, once it's uploaded for it to generate a forum link to the download that can be posted in the forums.

So like this sort of thing form wise:

Page 1 - Upload form, Made up of:
Text entry that allows users to make a name for the file.
The upload box
Upload button.

Page 2 - Forum codes
A box that contains a URL for the download, as well as one the contains a hyperlink with the name as the link.

By forum codes, I mean ones like below.



File Name (http://www.example.com/)

Any help would be great. Thanks.

Nile
02-23-2009, 10:49 PM
How about this:


<?php
$types = array("image/png","text/html","text/js","text/css");
if(isset($_POST['submit'])){
$error = true;
foreach($types as $type){
if($_FILES['uploadedfile']['type'] == $type){
$error = false;
}
}
if(!$error){
$target_path = "uploads/";
$target_path = $target_path . rand(0, getrandmax()) . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "Your file has been uploaded to <a href='".$target_path."'>".$target_path."</a> The code to upload it to the forum is: <br /><input type='text' readOnly='true' onclick='this.select();' value='".$target_path." (http://mysite.com/".$target_path.")' />";
} else{
echo "There was an error uploading the file, please try again!";
}
} else if($_FILES['uploadedfile']['name'] != ""){
echo "Looks like you have a ".$_FILES["uploadedfile"]["type"]." type! You can't!";
} else {
echo "No file";
}
} else { echo "No data!"; }
?>