greetings, fellow internet!

welcome to digitalgangster.com, the coolest community for people who hack the gibson and make bajillions of dollars off of online marketing. please click here to register an account (it's free) and join in on a plethora of discussions with the internet elite.

ASGPHE,
ytcracker, original digital gangster
follow me on twitter
fan me on facebook
Results 1 to 7 of 7

Thread: New IT assignment

  1. #1
    Super Moderator tispe's Avatar
    Join Date
    Aug 2006
    Location
    Jer-Z
    Posts
    18,814

    Default New IT assignment

    create a website that will:
    1. let the user upload either a .gif or a .doc
    2. have radio buttons on the form to determine if the code should overwrite a file with the same name or not.
    3. a password should be in the php to authorize the request
    4. echo the descriptions of the results back to the uploader
    This is my form:
    Code:
    <html>
    
    <head>
    <title>IT 202 Assignment 8</title>
        <!--  <link rel="stylesheet" type="text/css" href="assignment7.css">  -->
    </head>
    
    
    <body>
    
    <form enctype="multipart/form-data" action="upload.php" method="POST">
    Please choose a file: <input name="uploaded" type="file" /><br />
    <input type="radio" name="overwrite" value="overwrite"> Overwrite the file?<br>
    <input type="submit" value="Upload" />
    <input type="reset" value="RESET!"/>
    </form>
    
    </body>
    
    
    </html>
    this is my php code
    Code:
    <?php
    $target = "upload/";
    $target = $target . basename( $_FILES['uploaded']['name']) ;
    $ok=1;
    
    //This is our size condition
    if ($uploaded_size > 30000)
    {
    echo "Your file is too large.<br>";
    $ok=0;
    }
    
    //Here we check that $ok was not set to 0 by an error
    if ($ok==0)
    {
    Echo "Sorry your file was not uploaded";
    }
    
    //If everything is ok we try to upload it
    else
    {
    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
    {
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br>"
    echo $_FILES["uploadedfile"][ "name" ]
    echo $_FILES["uploadedfile"][ "type"  ]
    echo $_FILES["uploadedfile"][ "size"   ]
    echo $_FILES["uploadedfile"][ "error "]
    echo $_FILES["uploadedfile"][ "tmp_name" ]
    }
    else
    {
    echo "Sorry, there was a problem uploading your file.";
    }
    }
    
    
    ?>
    I'm not sure how to limit the filetype to gifs or docs, i've searched a few pages but nothing works for me and everything says something different. I'm also not sure how to get the radio button to work with the php to overwrite or how to get the password in there

  2. #2
    yung skeet pulaskeet's Avatar
    Join Date
    Jan 2007
    Location
    atlanta and nyc
    Posts
    1,000

    Default

    before you move the uploaded file type, look at $_FILES['userfile']['type'].

    this will give the mime type of the file.

    you can find a list of mime types at http://www.iana.org/assignments/media-types/

    and you can read more about the attributes of $_FILE at http://us2.php.net/features.file-upload

  3. #3
    Super Moderator tispe's Avatar
    Join Date
    Aug 2006
    Location
    Jer-Z
    Posts
    18,814

    Default

    Quote Originally Posted by pulaskeet View Post
    before you move the uploaded file type, look at $_FILES['userfile']['type'].

    this will give the mime type of the file.

    you can find a list of mime types at http://www.iana.org/assignments/media-types/

    and you can read more about the attributes of $_FILE at http://us2.php.net/features.file-upload
    err not helping i understand the attribute of $_FILE i dont understand why my files aren't uploading and how to make a password in my php and shit

  4. #4
    yung skeet pulaskeet's Avatar
    Join Date
    Jan 2007
    Location
    atlanta and nyc
    Posts
    1,000

    Default

    that was in reference to getting the file type. as far as the password, did you just want a static password or were you looking for it to be in a database? it's a pretty vague question.

    if it's a static password, just pass it in as a parameter, then check what the parameter value is.

    so for instance, upload.php?password=asdf1234, check $_POST['password'] and see if its asdf1234. if you're trying to establish a userbase, look at http://www.php-mysql-tutorial.com/

  5. #5
    Super Moderator tispe's Avatar
    Join Date
    Aug 2006
    Location
    Jer-Z
    Posts
    18,814

    Default

    nah it would just have to be static password dude idk where that would go in the code and how it would include in the form

  6. #6

    Default

    Quote Originally Posted by tispe View Post
    Code:
    <html>
    
    <head>
    <title>IT 202 Assignment 8</title>
        <!--  <link rel="stylesheet" type="text/css" href="assignment7.css">  -->
    </head>
    
    
    <body>
    
    <form enctype="multipart/form-data" action="upload.php" method="POST">
    Please choose a file: <input name="uploaded" type="file" /><br />
    <input type="radio" name="overwrite" value="overwrite"> Overwrite the file?<br />
    <input type="password" name="password" size="10" /><br />
    <input type="submit" value="Upload" />
    <input type="reset" value="RESET!"/>
    </form>
    
    </body>
    
    
    </html>
    this is my php code
    Code:
    <?php
    
    $yourpassword = "penispenispenis";
    
    if ($_POST["password"] != $yourpassword) {
    echo "try penispenispenis next time";
    exit();
    }
    
    $target = "/full/path/to/this/folder/goes/here/upload/";
    $target = $target . basename( $_FILES['uploaded']['name']) ;
    $ok=1;
    
    //This is our size condition
    if ($uploaded_size > 30000)
    {
    echo "Your cock is too large.<br>";
    $ok=0;
    }
    
    //Here we check that $ok was not set to 0 by an error
    if ($ok==0)
    {
    Echo "Sorry your file was not uploaded";
    }
    
    //If everything is ok we try to upload it
    else
    {
    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
    {
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br>"
    echo $_FILES["uploadedfile"][ "name" ]
    echo $_FILES["uploadedfile"][ "type"  ]
    echo $_FILES["uploadedfile"][ "size"   ]
    echo $_FILES["uploadedfile"][ "error "]
    echo $_FILES["uploadedfile"][ "tmp_name" ]
    }
    else
    {
    echo "Sorry, there was a problem uploading your nudes.";
    }
    }
    
    
    ?>
    there u go

  7. #7
    yung skeet pulaskeet's Avatar
    Join Date
    Jan 2007
    Location
    atlanta and nyc
    Posts
    1,000

    Default

    Quote Originally Posted by gza View Post
    echo "Sorry, there was a problem uploading your nudes.";

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
  •