Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default TAD OF PHP HELP +REP

    Hello,

    I'm trying to make an uploader that when you upload a file, it uploads it to a directory (the path contains a variable but i don't think that's a problem). So anyway, that bit is straight forward. But then I want it to post something, to do with the file it's just uploaded. I want it to post a path, then the file that was just uploaded's name name. So, here is my code:

    The form:

    Code:
    <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 />
    <input type="submit" value="Upload File" />
    </form>
    The code found on uploader.php:

    Code:
    <?
    
    // Where the file is going to be placed 
    $target_path = "/home/shoutcas/public_html/autodj/". $valid_user ."/";
    
    /* Add the original filename to our target path.  
    Result is "uploads/filename.extension" */
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
    $_FILES['uploadedfile']['tmp_name'];  
    
    $target_path = "/home/shoutcas/public_html/autodj/". $valid_user ."/";
    
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
    
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        if($_SERVER['REQUEST_METHOD'] != "GET") 
    {
    $filename = $_FILES['uploadedfile']['name'];
    $fd = fopen("/home/shoutcas/public_html/autodj/". $valid_user ."/playlist.lst","w"); 
    fwrite($fd, "/home/shoutcas/public_html/autodj/". $valid_user ."/". $filename ." |\n");
    }
        echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
        " has been uploaded and added to the playlist.";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    
    ?>
    Now, when I upload a file, it always gives me the "else" part (aka the error and it's failed).

    Can anybody spot anything that's wrong?

    Thanks in advance, I will give +rep of course. I may be having a few more posts, if I see you continuing to contribute to help me with problems I will be giving a gift in £ or HCs.
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


  2. #2
    Join Date
    Mar 2008
    Location
    England, Cheshire.
    Posts
    173
    Tokens
    0

    Default

    Its smarter to use a php variable to check the max size of the file.
    You might also want to make it check the extension? Say if they were to "accedently" upload & run a linux executable virus. Bibi server.

  3. #3
    Join Date
    Nov 2007
    Location
    London
    Posts
    1,577
    Tokens
    36

    Latest Awards:

    Default

    Quote Originally Posted by IntaMedia View Post
    Its smarter to use a php variable to check the max size of the file.
    You might also want to make it check the extension? Say if they were to "accedently" upload & run a linux executable virus. Bibi server.
    Thanks for that.

    I'm closing the thread now, no longer need help for this.
    Kind Regards,

    Guy
    __________________

    Since 2007. Unbelievable Uptime. Web hosting, resellers, master resellers, linux VPS, windows VPS, shoutcasts, at the lowest prices on the net.
    Tech-Hosts.co.uk.


Posting Permissions

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