Results 1 to 2 of 2

Thread: .php upload form...

  1. #1
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation .php upload form...

    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.

    PHP Code:
    [url] [/url]
    [
    url=http://www.example.com/]File Name[/url] 
    Any help would be great. Thanks.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    How about this:
    PHP Code:
    <?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(0getrandmax()) . 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='[url=http://mysite.com/".$target_path."]".$target_path."[/url]' />";
         } 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!"; }
    ?>
    Jeremy | jfein.net

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •