file upload problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ljuljacka

    file upload problem

    I'm just trying to run a fileupload script from the manual, just to see how
    it works, and it won't. I've checked if file upload is enabled and it is.
    Also, the file I'm trying to upload is smaller then max. The folder I'm
    trying to upload files to is ./ispit1. I always get the "wrong" echo from
    the script when I run debug in my editor and when I run it in my browser
    (firefox) I get the following message:
    "The requested URL /ispit/__URL__ was not found on this server."
    The file isn't transfered to tmp directory either.
    Any help is welcome.

    <form enctype="multip art/form-data" action="__URL__ " method="POST">
    <input type="hidden" name="MAX_FILE_ SIZE" value="30000" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
    </form>


    <?php
    $uploaddir = './ispit1/';
    $uploadfile = $uploaddir . basename($_FILE S['userfile']['name']);

    if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
    } else {
    echo "Possible file upload attack!\n";
    }
    ?>


  • FlungaBunga

    #2
    Re: file upload problem

    Hey,

    Probably just look at the basics first.

    you've selected the destination folder to be './ispit1', which is a
    relative file path. I would recommend that you provide the script with
    an absolute path to the destination so that regardless where you
    execute your script from you'll be moving the files into the correct
    folder. That'll make debugging the script much easier as you won't be
    searching the file system for ispit1 folders ;)

    Let us know how you go :)


    On Oct 12, 10:01 am, "ljuljacka" <ljulja...@yaho o.comwrote:
    I'm just trying to run a fileupload script from the manual, just to see how
    it works, and it won't. I've checked if file upload is enabled and it is.
    Also, the file I'm trying to upload is smaller then max. The folder I'm
    trying to upload files to is ./ispit1. I always get the "wrong" echo from
    the script when I run debug in my editor and when I run it in my browser
    (firefox) I get the following message:
    "The requested URL /ispit/__URL__ was not found on this server."
    The file isn't transfered to tmp directory either.
    Any help is welcome.
    >
    <form enctype="multip art/form-data" action="__URL__ " method="POST">
    <input type="hidden" name="MAX_FILE_ SIZE" value="30000" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
    </form>
    >
    <?php
    $uploaddir = './ispit1/';
    $uploadfile = $uploaddir . basename($_FILE S['userfile']['name']);
    >
    if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";} else { echo "Possible file upload attack!\n";}?>

    Comment

    • Johnny

      #3
      Re: file upload problem


      "FlungaBung a" <IanJamesGrant@ gmail.comwrote in message
      news:1160614668 .777264.106700@ h48g2000cwc.goo glegroups.com.. .
      <snip/>
      On Oct 12, 10:01 am, "ljuljacka" <ljulja...@yaho o.comwrote:

      And do us all a favor ljuljacka:
      if you must post to more than one group, do it in the one meesage so that
      all replies go to all groups at once.

      Right now this message is only in comp.lang.php but you have another
      separate thread going on the exact same subject in alt.php with no conectio
      to these messages>
      and it's not like this is the very first time you've posted here....



      Comment

      • ljuljacka

        #4
        Re: file upload problem

        Sorry again...tnx FlungaBunga for the suggestion...th is script is working on
        my laptop and for some reason it won't work on my desktop comp...all the
        settings are the same....again.. .sorry for multipost...lik e I said on
        alt.php some groups don't like it


        "Johnny" <removethis.huu anito@hotmail.c omwrote in message
        news:WOgXg.1184 $UJ2.963@fed1re ad07...
        >
        "FlungaBung a" <IanJamesGrant@ gmail.comwrote in message
        news:1160614668 .777264.106700@ h48g2000cwc.goo glegroups.com.. .
        <snip/>
        On Oct 12, 10:01 am, "ljuljacka" <ljulja...@yaho o.comwrote:
        >
        And do us all a favor ljuljacka:
        if you must post to more than one group, do it in the one meesage so that
        all replies go to all groups at once.
        >
        Right now this message is only in comp.lang.php but you have another
        separate thread going on the exact same subject in alt.php with no
        conectio
        to these messages>
        and it's not like this is the very first time you've posted here....
        >
        >
        >

        Comment

        • ljuljacka

          #5
          Re: file upload problem

          settings are the same....again.. .sorry for multipost...lik e I said on
          alt.php some groups don't like it
          >
          >
          crossposting I mean :)


          Comment

          • Johnny

            #6
            Re: file upload problem


            I guess instead of complaing about it I should of joined the thread back
            together like I'm doing now :-( see below for the next installment, hmm I
            wonder if this really will stitch the thread back together...like where will
            it end up in alt.php...we'll see

            On Oct 12, 10:01 am, "ljuljacka" <ljulja...@yaho o.comwrote:
            I'm just trying to run a fileupload script from the manual, just to see
            how
            it works, and it won't. I've checked if file upload is enabled and it is.
            Also, the file I'm trying to upload is smaller then max. The folder I'm
            trying to upload files to is ./ispit1. I always get the "wrong" echo from
            the script when I run debug in my editor and when I run it in my browser
            (firefox) I get the following message:
            "The requested URL /ispit/__URL__ was not found on this server."
            The file isn't transfered to tmp directory either.
            Any help is welcome.
            >
            <form enctype="multip art/form-data" action="__URL__ " method="POST">
            <input type="hidden" name="MAX_FILE_ SIZE" value="30000" />
            Send this file: <input name="userfile" type="file" />
            <input type="submit" value="Send File" />
            </form>
            >
            <?php
            $uploaddir = './ispit1/';
            $uploadfile = $uploaddir . basename($_FILE S['userfile']['name']);
            >
            if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile)) {
            echo "File is valid, and was successfully uploaded.\n";} else { echo
            "Possible file upload attack!\n";}?>

            "FlungaBung a" <IanJamesGrant@ gmail.comwrote in message
            news:1160614668 .777264.106700@ h48g2000cwc.goo glegroups.com.. .
            Hey,

            Probably just look at the basics first.

            you've selected the destination folder to be './ispit1', which is a
            relative file path. I would recommend that you provide the script with
            an absolute path to the destination so that regardless where you
            execute your script from you'll be moving the files into the correct
            folder. That'll make debugging the script much easier as you won't be
            searching the file system for ispit1 folders ;)

            Let us know how you go :)

            "Johnny" <removethis.huu anito@hotmail.c omwrote in message

            Every LAMP server I've worked on doesn't have write file permission to do
            the move. PHP always seems to run as 'other' and to allow wriet permssions
            on 'other' would not seem to be a good thing. The way I have been able to
            do it is by incorporating PHP FTP functions and moving the file with them.

            Here's how I debug by putting this at the top of the file posted to right
            after the opening php tag:
            var_dump($_FILE S);
            and see what's happening.
            Most likely its permissions though
            --------------------------
            OK next installment:
            2 problems:
            "The requested URL /ispit/__URL__ was not found on this server."
            you don't know where your directory is (FlungaBunga advice above is good
            place to start)
            The file isn't transfered to tmp directory either
            and the upload doesn't seem to arrive

            So to debug the first problem do this:

            echo "<br />cwd=".getcwd() ; # show where you are, this'll help u figure
            where ./ispit1/ goes to
            if ($handle = opendir($upload dir)) { # in php5 use scandir to replace this
            block
            /* This is the correct way to loop over the directory. */
            while (false !== ($file = readdir($handle ))) {
            echo "$file<br />";
            }
            } else {
            echo "<br />could not open that directory<br />";
            }

            for the second problem use var_dump($_FILE S); on entry to your script to
            see where stuff goes.

            with those tools and FlungaBunga's advice you should have this solved in
            short order. Good luck :-)









            Comment

            • ljuljacka

              #7
              Re: file upload problem

              first of all tnx for all the help, great people here :)

              I tried this code for debuging that you suggested, and on while line I get
              this error: "readdir():supp lied argument is not a valid directory resource
              in C:\....\ispit\s cript.php"

              $uploaddir='isp it1/';
              if ($handle = opendir($upload dir)) { # in php5 use scandir to replace this
              block
              /* This is the correct way to loop over the directory. */
              while (false !== ($file = scandir($handle ))) {
              echo "$file<br />";
              }
              } else {

              echo "<br />could not open that directory<br />";
              }



              Comment

              • Johnny

                #8
                Re: file upload problem


                "ljuljacka" <ljuljacka@yaho o.comwrote in message
                news:egljkc$s20 $1@news1.carnet .hr...
                first of all tnx for all the help, great people here :)
                >
                I tried this code for debuging that you suggested, and on while line I get
                this error: "readdir():supp lied argument is not a valid directory resource
                in C:\....\ispit\s cript.php"
                >
                $uploaddir='isp it1/';
                if ($handle = opendir($upload dir)) { # in php5 use scandir to replace this
                block
                /* This is the correct way to loop over the directory. */
                while (false !== ($file = scandir($handle ))) {
                echo "$file<br />";
                }
                } else {
                >
                echo "<br />could not open that directory<br />";
                }
                >
                >
                so do you see the file upload now when you use var_dump($_FILE S);? as in
                have you fixed the first problem?

                as for the 2nd:

                try this to see if you can see ispit where you think it is
                <?php
                if ($handle = opendir(getcwd( ))) {
                while (false !== ($file = readdir($handle ))) {
                echo "$file<br />";
                }
                } else {
                echo "<br />could not open that directory<br />";
                }
                ?>

                that should show you if the dir you want is where you want it.
                It looks from your code as if the ispit dir is at the same level as your
                script but the results of running the other code say it's not.
                What does the new code show? is it there? if not then $uploaddir='isp it1/';
                won't be valid
                if you have your script in say
                c:/mysqripts/thescript.php
                then your code is now pointing at an upload dir of
                c:/myscripts/ispit

                I don't think this is a difficult problem...

                and please put your reply under here insetad of top posting. |
                |
                v


                Comment

                Working...