Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2005
    Location
    London
    Posts
    9,773
    Tokens
    146

    Latest Awards:

    Default Help me with this PHP upload script

    Well first of here's a upload script i'm trying to edit:
    PHP Code:
                                  <?php require('head.php');?>
    <center><style>
    body {
    font-family: Franklin Gothic Book;
    font-size: 12px;
    font color: #efefef;
    }
    input {
    border: 1px solid #efefef;
    font-family: Franklin Gothic Book;
    font-size: 12px;
    font color: #efefef;
    }
    img {
    border: 1px solid #efefef;
    }
    </style>
    </head>
    <form action="upload.php" method="post" enctype="multipart/form-data">
    Browse a File to Upload:<br>
    <input type="file" name="filetoupload"><br>
    <input type="hidden" name="MAX_FILE_SIZE" value="<?echo $size_bytes?>">
    <br>
    <input type="Submit" value="Upload File">
    </form>
    <?php
    $upload_dir 
    "../danny/dan/"//change to whatever you want.
    // files less than 1MB
    $size_bytes 10000000000//bytes will be uploaded
    $limit_file_type "no"//Do you want to limit the types of files uploaded. (yes/no)
    // specify file types.
    $allowed_file_type = array('image/gif',
    'image/jpg');
    //check if the directory exist or not.
    if (!is_dir("$upload_dir")) {
    die (
    "The directory <b>($upload_dir)</b> doesn't exist");
    }
    //check if the directory is writable.
    if (!is_writeable("$upload_dir")){
    die (
    "The directory <b>($upload_dir)</b> is NOT writable, Please Chmod (777)");
    }
    //Check first if a file has been selected
    //is_uploaded_file('filename') returns true if
    //a file was uploaded via HTTP POST. Returns false otherwise.
    if (is_uploaded_file($_FILES['filetoupload']['tmp_name']))
    {
    //begin of is_uploaded_file
    //Get the Size of the File
    $size $_FILES['filetoupload']['size'];
    //Make sure that $size is less than 1MB (1000000 bytes)
    if ($size $size_bytes)
    {
    echo 
    "File Too Large. File must be <b>$size_bytes</b> bytes.";
    exit();
    }
    //check file type
    if (($limit_file_type == "yes") && (!in_array($_FILES['filetoupload']['type'],$allowed_file_type)))
    {
    echo
    "wrong file type";
    exit();
    }
    // $filename will hold the value of the file name submetted from the form.
    $filename $_FILES['filetoupload']['name'];
    // Check if file is Already EXISTS.
    if(file_exists($upload_dir.$filename)){
    echo 
    "
    <table border='1' style='border-collapse: collapse' bordercolor='#FF0000' bgcolor='#EFEFEF'>
    <tr>
    <td><font family='Franklin Gothic Book' size='1' color='#FF0000'>
    $filename already exists on our servers!</font></td>
    </tr>
    </table>
    "
    ;
    exit();
    }
    //Move the File to the Directory of your choice
    //move_uploaded_file('filename','destination') Moves afile to a new location.
    if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {
    //tell the user that the file has been uploaded and make him alink too;).
    echo "<img src='$upload_dir$filename'> <br>
    Direct link<br>
    <input size='60' value='http://www.hhgs.net/danny/dan/
    $filename'>";
    exit();
    }
    else
    {
    //Print error
    echo "
    <table border='1' style='border-collapse: collapse' bordercolor='#FF0000' bgcolor='#EFEFEF'>
    <tr>
    <td><font family='Franklin Gothic Book' size='1' color='#FF0000'>There was a problem moving your file</font></td>
    </tr>
    </table>
    "
    ;
    exit();
    }
    }
    //end of is_uploaded_file
    ?>
    </center>
    <?php require('bottom.php');?>
    I want to change it when the server checks if the file exists with this code:
    PHP Code:
    if(file_exists($upload_dir.$filename)) 
    instead of echo'ing out the following:
    PHP Code:
    echo "
    <table border='1' style='border-collapse: collapse' bordercolor='#FF0000' bgcolor='#EFEFEF'>
    <tr>
    <td><font family='Franklin Gothic Book' size='1' color='#FF0000'>
    $filename already exists on our servers!</font></td>
    </tr>
    </table>
    "

    I want it to delete the file, i've tried replacing it with:
    PHP Code:
    Unlink($upload_dir.$filename
    But I keep getting several different errors , i'm guessing it all has to be looped or something so either way someone fix it for 49 rep points.
    Last edited by --ss--; 30-12-2007 at 06:52 PM.

  2. #2
    Join Date
    Oct 2005
    Location
    Spain, Valencia
    Posts
    20,492
    Tokens
    3,575
    Habbo
    GoldenMerc

    Latest Awards:

    Default

    + my 24 rep power so 73 rep for this :]

  3. #3
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    PHP Code:
                                  <?php require('head.php');?>
    <center><style>
    body {
    font-family: Franklin Gothic Book;
    font-size: 12px;
    font color: #efefef;
    }
    input {
    border: 1px solid #efefef;
    font-family: Franklin Gothic Book;
    font-size: 12px;
    font color: #efefef;
    }
    img {
    border: 1px solid #efefef;
    }
    </style>
    </head>
    <form action="upload.php" method="post" enctype="multipart/form-data">
    Browse a File to Upload:<br>
    <input type="file" name="filetoupload"><br>
    <input type="hidden" name="MAX_FILE_SIZE" value="<?echo $size_bytes?>">
    <br>
    <input type="Submit" value="Upload File">
    </form>
    <?php
    $upload_dir 
    "../danny/dan/"//change to whatever you want.
    // files less than 1MB
    $size_bytes 10000000000//bytes will be uploaded
    $limit_file_type "no"//Do you want to limit the types of files uploaded. (yes/no)
    // specify file types.
    $allowed_file_type = array('image/gif',
    'image/jpg');
    //check if the directory exist or not.
    if (!is_dir("$upload_dir")) {
    die (
    "The directory <b>($upload_dir)</b> doesn't exist");
    }
    //check if the directory is writable.
    if (!is_writeable("$upload_dir")){
    die (
    "The directory <b>($upload_dir)</b> is NOT writable, Please Chmod (777)");
    }
    //Check first if a file has been selected
    //is_uploaded_file('filename') returns true if
    //a file was uploaded via HTTP POST. Returns false otherwise.
    if (is_uploaded_file($_FILES['filetoupload']['tmp_name']))
    {
    //begin of is_uploaded_file
    //Get the Size of the File
    $size $_FILES['filetoupload']['size'];
    //Make sure that $size is less than 1MB (1000000 bytes)
    if ($size $size_bytes)
    {
    echo 
    "File Too Large. File must be <b>$size_bytes</b> bytes.";
    exit();
    }
    //check file type
    if (($limit_file_type == "yes") && (!in_array($_FILES['filetoupload']['type'],$allowed_file_type)))
    {
    echo
    "wrong file type";
    exit();
    }
    // $filename will hold the value of the file name submetted from the form.
    $filename $_FILES['filetoupload']['name'];
    // Check if file is Already EXISTS.
    if(file_exists($upload_dir.$filename)){

    chmod($upload_dir.$filename0777); // Makes sure file is deletable
    unlink($upload_dir.$filename);

    }
    //Move the File to the Directory of your choice
    //move_uploaded_file('filename','destination') Moves afile to a new location.
    if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {
    //tell the user that the file has been uploaded and make him alink too;).
    echo "<img src='$upload_dir$filename'> <br>
    Direct link<br>
    <input size='60' value='http://www.hhgs.net/danny/dan/
    $filename'>";
    exit();
    }
    else
    {
    //Print error
    echo "
    <table border='1' style='border-collapse: collapse' bordercolor='#FF0000' bgcolor='#EFEFEF'>
    <tr>
    <td><font family='Franklin Gothic Book' size='1' color='#FF0000'>There was a problem moving your file</font></td>
    </tr>
    </table>
    "
    ;
    exit();
    }
    }
    //end of is_uploaded_file
    ?>
    </center>
    <?php require('bottom.php');?>
    That should work..if not, please tell me the error

  4. #4
    Join Date
    Oct 2005
    Location
    Spain, Valencia
    Posts
    20,492
    Tokens
    3,575
    Habbo
    GoldenMerc

    Latest Awards:

    Default

    I get this at the top
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/hhgsnet/public_html/radiodjpanel/upload.php:1) in /home/hhgsnet/public_html/radiodjpanel/check.php on line 2
    But it seems to work?
    Not sure if its working properly tho it makes the upload go right down the page

  5. #5
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    That has nothing to do with the code I posted..?

  6. #6
    Join Date
    Oct 2005
    Location
    Spain, Valencia
    Posts
    20,492
    Tokens
    3,575
    Habbo
    GoldenMerc

    Latest Awards:

    Default

    This uploader goes into RadioDJ Panel

  7. #7
    Join Date
    Aug 2005
    Location
    London
    Posts
    9,773
    Tokens
    146

    Latest Awards:

    Default

    Quote Originally Posted by Invent View Post
    That has nothing to do with the code I posted..?
    The upload script goes into the dj panel he uses

Posting Permissions

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