Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHp upload script help

Options
  • 01-02-2003 3:56am
    #1
    Registered Users Posts: 9,511 ✭✭✭


    i am trying to set up a script which will only allow the following 3 file formats to be uploaded. gif jpeg jpg i can get it to work for gif but how to i edit this peice of code for the other two to work.

    The bit in red is the problem.
    <?php
    $dir = "screenshots/";

    if ($_POST["files"]) {
    if (!file_exists($dir . $_FILES["file"]["name"]))
    if (($file_type=="image/gif") || ($file_type=="image/jpeg")) {
    copy($_FILES["file"]["tmp_name"], $dir . $_FILES["file"]["name"]);
    $file = $_FILES["file"]["name"];
    $headers = "From: sceenshots@cmeire.com";
    $host = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
    $ip = $_SERVER["REMOTE_ADDR"];
    $subject = "Screenshot uploaded"; // your webpage
    $time = date("d F Y") . " @ " . date("H:i");
    $to = "admin@cmeire.com"; // your email
    $message = "File: " . $file . "\nHost: " . $host . "\nIP: " . $ip . "\nTime: " . $time;
    mail($to, $subject, $message, $headers);
    }

    else {
    print("Filename already exists.<br /><br />\n");
    }
    }
    ?>
    <table>
    <?php
    $count = 0;
    $filesArray = array();

    $handle = opendir("screenshots/");

    while ($file = readdir($handle)) {
    if ($file != "." && $file != "..") {
    $filesArray[$count] = $file;
    $count++;
    }
    }

    closedir($handle);

    array_multisort($filesArray, SORT_ASC, SORT_REGULAR);


    ?>


Comments

  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Com'on! It's not that difficult!

    You're already checking if the filetype is image/jpeg or image/gif so to check for a filetype of image/jpg, you would add what to that if statement..?

    (I assume you're not interested in checking for jpe filetypes, btw)


  • Registered Users Posts: 9,511 ✭✭✭irishgeo


    an and or and or statemnt which is what in php


  • Registered Users Posts: 1,562 ✭✭✭Snaga


    The if statement you have already has an OR in it.

    If ((stuff = blah) || (stuff = blah2) || (stuff = blah3) || etc etc etc...


    if (($file_type=="image/gif") || ($file_type=="image/jpeg")) { 
                                  ^^
    


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Would you like us to cut up your food for you now?

    :rolleyes: :p


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    I feel I should add to this public shaming...

    The if statement you have already has an OR in it.

    If ((stuff = blah) || (stuff = blah2) || (stuff = blah3) || etc etc etc...


    ...in fact, PHP has made it almost foolproof for you...

    [php]if (($stuff == $blah) OR ($stuff == $blah2) or ...[/php]adam


  • Advertisement
  • Registered Users Posts: 9,511 ✭✭✭irishgeo


    what happen to someone just posting the bloddy answer and treating you as if it was school by spoon feeding you little bits of info.

    Even with the or in the ****ing thing still doesnt work i have played around with it for ages.

    I only post problems when i cant figure it out myse

    :mad:


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Most of the people who responded to you will never, ever just give "the bloddy answer" and leave it at that. It sets a bad precendent. You'll see why when you've coded a bit more.

    http://ie.php.net/manual/en/language.operators.logical.php

    adam


  • Registered Users Posts: 9,511 ✭✭✭irishgeo


    i got it guys. I finally figured it out. :D:D:D:D:D:D:D:D

    Now i am not likely to forget it that i figured out myself. If you had told me i would have forgotten it.

    Fixed code is below
    if (($file_type=="image/gif" Or "image/jpeg" Or "image/jpg"))

    I kep using the $file_type string after each OR.

    Thanks agian.


Advertisement