#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    17
    Rep Power
    0

    Problem with uoloading picture


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Upload</title>
    </head>
    <body>
    <form action="upload.php" enctype="multipart/form-data" method="post">
    Last Name:<br /> <input type="text" name="name" value="" /><br />
    Homework #1:<br /> <input type="file" name="homework1" value="" /><br />
    Homework #2:<br /> <input type="file" name="homework2" value="" /><br />
    <p><input type="submit" name="submit" value="Submit Notes" /></p>
    </form>
    <?php
    /*echo "that was not correct";
    $business_unite = $_POST['name'];
    $catergory = $_POST['catergory'];
    $image1 = $_POST['image1'];
    $image2 = $_POST["image2"];
    $services = $_POST["image1"];
    $street = $_POST["image1"];
    $location = $_POST["location"];
    */
    if (isset($_FILES['picture1']) or isset($_FILES['picture2'],$_FILES['picture3']))
    {
    if (is_uploaded_file($_FILES['image1']['tmp_name']) &&
    is_uploaded_file($_FILES['image2']['tmp_name']))
    {
    if ( ($_FILES['image1']['type'] != "application/gif ||application/png || application/png ||application/jpeg||application/bmp||application/psd application/tif|| application/thm ||application/tuV " ) ||

    $_FILES['image2']['type'] != "application/gif ||application/png || application/png ||application/jpeg||application/bmp||application/psd application/tif|| application/thm ||application/tuV " )
    {
    echo "<p>File format not accepted.</p>";
    exit ;
    }
    /* Format date and create daily directory, if necessary. */

    if($new_category){
    $path=mkdir("pictures"."/".$category."/".$bissiness_unte);
    echo "was not found";
    }
    else{
    $path=mkdir("images/$bussiness_unite");
    echo 'was found';
    }
    function count_files ($dir) { $count = count(glob($_SERVER['DOCUMENT_ROOT'].$dir . "*")) ;
    return $count;

    }

    $image1 = $_POST['name'].$number;
    $result = move_uploaded_file($_FILES['Picture1']['tmp_name'],$path);
    if ($result == 1) echo "<p> image1 successfully uploaded.</p>";
    else echo "<p>There was a problem uploading homework #1.</p>";
    /* Name and move homework #2 */
    $images2 = $_POST['name']."$number++";
    $result = move_uploaded_file($_FILES['Pictures2']['tmp_name'],$path);
    if ($result == 1) echo "<p>image2 successfully uploaded.</p>";
    else echo "<p>There was a problem uploading homework #2.</p>";
    echo "<p>There was a problem uploading homework #1.</p>";
    } #endif

    }
    ?>
    </body>
    </html>
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,730
    Rep Power
    1959
    Please specify what and where you have problem. Do you get any error message?

    One thing you can start to look at is your if statement:
    Code:
    $_FILES['image1']['type'] != "application/gif || application/png || ...
    You will have to specify the variable for each comparison:
    Code:
    $_FILES['image1']['type'] != "application/gif || $_FILES['image1']['type'] !=application/png || $_FILES['image1']['type'] !=...
    When you post code, please use the code tags.
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    westside, please read the new user guide.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    17
    Rep Power
    0

    when i run the script it shows no error but the upload does not work


    when i run the script it shows no error but the upload does not work
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Did you read the new user guide? I doubt you did.

    Your input is named homework1. What is your code looking for?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    48
    Rep Power
    3
    For the sake of anyone hoping to answer the question, I am going to repost this code in a more readable format.

    PHP Code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Upload</title>
    </head>
    <body>
        <form action="upload.php" enctype="multipart/form-data" method="post">
            Last Name:<br /> <input type="text" name="name" value="" /><br />
            Homework #1:<br /> <input type="file" name="homework1" value="" /><br />
            Homework #2:<br /> <input type="file" name="homework2" value="" /><br />
            <p><input type="submit" name="submit" value="Submit Notes" /></p>
        </form>
        <?php 
    /*echo "that was not correct";
    $business_unite = $_POST['name'];
    $catergory = $_POST['catergory'];
    $image1 = $_POST['image1'];
    $image2 = $_POST["image2"];
    $services = $_POST["image1"];
    $street = $_POST["image1"];
    $location = $_POST["location"];
    */
    if (isset($_FILES['picture1']) or isset($_FILES['picture2'],$_FILES['picture3']))
    {
        if (
    is_uploaded_file($_FILES['image1']['tmp_name']) &&
            
    is_uploaded_file($_FILES['image2']['tmp_name']))
        {
            if ( (
    $_FILES['image1']['type'] != "application/gif ||application/png ||
                application/png ||application/jpeg||application/bmp||
                application/psd application/tif|| application/thm ||application/tuV     " 
    ) ||

                
    $_FILES['image2']['type'] != "application/gif ||application/png ||
                application/png ||application/jpeg||application/bmp||application/psd
                application/tif|| application/thm ||application/tuV     " 
    )
            {
                echo 
    "<p>File format not accepted.</p>";
                exit ;
            } 
            
    /* Format date and create daily directory, if necessary. */

            
    if($new_category){
                
    $path=mkdir("pictures"."/".$category."/".$bissiness_unte);
                echo 
    "was not found";
            } 
            else{
                
    $path=mkdir("images/$bussiness_unite");
                echo 
    'was found'
            } 

            function 
    count_files ($dir) {
                
    $count count(glob($_SERVER['DOCUMENT_ROOT'].$dir "*")) ;
                return 
    $count
                }

            
    $image1 $_POST['name'].$number;
            
    $result move_uploaded_file($_FILES['Picture1']['tmp_name'],$path);
            if (
    $result == 1) {
                echo 
    "<p> image1 successfully uploaded.</p>";
            }
            else {
                echo 
    "<p>There was a problem uploading homework #1.</p>";
            }

            
    /* Name and move homework #2 */
            
    $images2 $_POST['name']."$number++";
            
    $result move_uploaded_file($_FILES['Pictures2']['tmp_name'],$path);
            if (
    $result == 1) {
                echo 
    "<p>image2 successfully uploaded.</p>";
            }
            else {
                echo 
    "<p>There was a problem uploading homework #2.</p>";
            }
            echo 
    "<p>There was a problem uploading homework #1.</p>";
        } 
    #endif

    }
    ?>
    </body>
    </html>
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    westside, every line in your code handling the $_FILES array is wrong.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    48
    Rep Power
    3
    Now, WESTSIDE200, I can see a few things wrong with your code.

    1. You cannot put your comparison operators inside a string
    You can't do this:
    PHP Code:
    $_FILES['image2']['type'] != "application/gif ||application/png || //etc. etc. etc. 
    Instead, you would have to do this:
    PHP Code:
    $_FILES['image2']['type'] != "application/gif" && $_FILES['image2']['type'] != "application/png" //etc. etc. etc. 
    2. You are using inconsistent variable names.
    You say in your opening code that $_POST['name'] is set to $business_unite, however, further down you refer to that variable as $bissiness_unte and later on as $bussiness_unite. While we're at it, did you notice that your value transfers ($business_unite = $_POST['name'], etc.) are all commented out?


    A few other questions
    In order for us to help you out, you'll need to answer a few other questions too.

    1. The form in your code has an action set to "upload.php". Is this just a totally unrelated form? Why is it there?
    2. The form in the code you posted has no file uploads, yet the php you posted (if related) is checking for them. Why?
    3. Why is your initial if statement structured so strangely? (it only passes if the first picture is set, or if BOTH the second and third are set, or if all three are set).
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    17
    Rep Power
    0
    Originally Posted by ManiacDan
    westside, every line in your code handling the $_FILES array is wrong.
    PLEAESE COULD YOU HELP ME CORRECT IT
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    17
    Rep Power
    0
    Originally Posted by piperpam27
    Now, WESTSIDE200, I can see a few things wrong with your code.

    1. You cannot put your comparison operators inside a string
    You can't do this:
    PHP Code:
    $_FILES['image2']['type'] != "application/gif ||application/png || //etc. etc. etc. 
    Instead, you would have to do this:
    PHP Code:
    $_FILES['image2']['type'] != "application/gif" && $_FILES['image2']['type'] != "application/png" //etc. etc. etc. 
    2. You are using inconsistent variable names.
    You say in your opening code that $_POST['name'] is set to $business_unite, however, further down you refer to that variable as $bissiness_unte and later on as $bussiness_unite. While we're at it, did you notice that your value transfers ($business_unite = $_POST['name'], etc.) are all commented out?


    A few other questions
    In order for us to help you out, you'll need to answer a few other questions too.

    1. The form in your code has an action set to "upload.php". Is this just a totally unrelated form? Why is it there?
    2. The form in the code you posted has no file uploads, yet the php you posted (if related) is checking for them. Why?
    3. Why is your initial if statement structured so strangely? (it only passes if the first picture is set, or if BOTH the second and third are set, or if all three are set).

    OK I HAVE WILL TRY TO THE FORM HAS ACTION UPLOAD .PHP SO THAT IT SHOULD SUBMIT THE UPLOAD VARAIBLE TO THE UPLOAD.PHP SCRIPT
  20. #11
  21. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    You could try answering any question ever posed to you. Look at the thread, someone went through the effort of giving you two solutions (both of which I asked you direct questions about) and then asked you three more questions.

    This is not a resource where you can get experts to write code for you for free, we don't give out work here. Pay someone to do this, or answer the questions that are posed to you.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    17
    Rep Power
    0
    Originally Posted by ManiacDan
    You could try answering any question ever posed to you. Look at the thread, someone went through the effort of giving you two solutions (both of which I asked you direct questions about) and then asked you three more questions.

    This is not a resource where you can get experts to write code for you for free, we don't give out work here. Pay someone torn do this, or answer the questions that are posed to you.
    the form is intended to submit the varaible through post to the same page the page which has the code. and the form takes two files that is homework1 and homework2 so this are the names of the files at the time of upload
    i intended to make the first if pass if the the two pictures are set and the second if is intended to gain against a malicious user trying to trick the script
  24. #13
  25. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Get it working first, then add security checks like that (you did the check wrong).

    I'm going to ask you this one more time:


    Your input is named homework1. What is your code looking for?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    17
    Rep Power
    0
    thank u all for your contribution the problem has been solve
    Last edited by ManiacDan; October 3rd, 2012 at 05:06 PM.

IMN logo majestic logo threadwatch logo seochat tools logo