Upload problem

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

    #1

    Upload problem

    I do what most programmers do -- we steal code from stuff we have written
    before, or accept code from others that works, before we attempt to write
    something altogether new.

    On a previous project I wrote code to upload pictures and music from the
    local drive to the server. It worked perfectly. I scarfed that code,
    without changing any names, for a new project and I am running into a
    problem. Here is what I have:

    The form definition:
    <form action="" method="post" enctype="multip art/form-data" name="History"
    target="_self">
    <input type="hidden" name="MAX_FILE_ SIZE" value="1250000" >

    The file field:
    <input name="srcFile" type="file" id="srcFile">

    The code for the copying:
    if (strlen(trim($_ FILES['srcFile']['name'])) 0) {
    $tmp_photo = "pic_" . $user . "_" . $_POST['petname'] . "_" .
    $_FILES['srcFile']['name'];
    echo "target=" . $tmp_photo . "<br>";
    echo "src=" . $_FILES['srcFile']['tmp_name'] . "<br>";
    $status = copy ($_FILES['srcFile']['tmp_name'], $tmp_photo);
    echo "status=" . $status . "<br>";
    ---- more processing follows ----

    The result is:
    target=pic_shel donlg_coda_coda .jpg
    src=
    status=

    In other words, it is not finding a value for
    $_FILES['srcFile']['tmp_name'], but it is finding the value for
    $_FILES['srcFile']['name'] (that value is coda.jpg and is nested a number
    of directories down on the C drive).

    This worked fine before. Does anything leap out at anyone?

    While I am here, how do you folks handle the time delay in processing the
    upload to avoid having impatient users? So far, all I am doing is putting a
    message before the hit the key to do the upload.

    Shelly




  • Andy Hassall

    #2
    Re: Upload problem

    On Sun, 08 Oct 2006 22:19:34 GMT, "Shelly" <sheldonlg.news @asap-consult.com>
    wrote:
    >I do what most programmers do -- we steal code from stuff we have written
    >before, or accept code from others that works, before we attempt to write
    >something altogether new.
    >
    >On a previous project I wrote code to upload pictures and music from the
    >local drive to the server. It worked perfectly. I scarfed that code,
    >without changing any names, for a new project and I am running into a
    >problem. Here is what I have:
    >
    >The form definition:
    ><form action="" method="post" enctype="multip art/form-data" name="History"
    >target="_self" >
    <input type="hidden" name="MAX_FILE_ SIZE" value="1250000" >
    >
    >The file field:
    ><input name="srcFile" type="file" id="srcFile">
    >
    >The code for the copying:
    if (strlen(trim($_ FILES['srcFile']['name'])) 0) {
    $tmp_photo = "pic_" . $user . "_" . $_POST['petname'] . "_" .
    $_FILES['srcFile']['name'];
    echo "target=" . $tmp_photo . "<br>";
    echo "src=" . $_FILES['srcFile']['tmp_name'] . "<br>";
    $status = copy ($_FILES['srcFile']['tmp_name'], $tmp_photo);
    Are you sure you don't want to actually use move_uploaded_f ile()?

    Also using $_POST['petname'] directly in the target filename without
    sanitising it (for at the very least things like "/" and "..") is potentially
    dangerous.
    echo "status=" . $status . "<br>";
    ---- more processing follows ----
    >
    >The result is:
    >target=pic_she ldonlg_coda_cod a.jpg
    >src=
    >status=
    >
    >In other words, it is not finding a value for
    >$_FILES['srcFile']['tmp_name'], but it is finding the value for
    >$_FILES['srcFile']['name'] (that value is coda.jpg and is nested a number
    >of directories down on the C drive).
    >
    >This worked fine before. Does anything leap out at anyone?
    Ask PHP for errors first:



    $_FILES fills in an 'error' subscript for each file. Do you also have
    error_reporting cranked up to the maximum level?
    >While I am here, how do you folks handle the time delay in processing the
    >upload to avoid having impatient users? So far, all I am doing is putting a
    >message before the hit the key to do the upload.
    Short answer, not much you can do. There were some longer answers in a recent
    file upload thread on this group:


    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • petersprc@gmail.com

      #3
      Re: Upload problem

      Maybe $_FILES['srcFile']['error'] has an error code? I would also make
      sure you have write permissions to PHP's upload_tmp_dir
      (ini_get('uploa d_tmp_dir') or phpinfo() will tell you where it is).

      As for long uploads, you could warn the user that the upload may take a
      while, or unhide a "Please Wait" image.

      There are a couple techniques for a real upload progress indicator,
      some of which are shown here:





      Shelly wrote:
      I do what most programmers do -- we steal code from stuff we have written src
      before, or accept code from others that works, before we attempt to write
      something altogether new.
      >
      On a previous project I wrote code to upload pictures and music from the
      local drive to the server. It worked perfectly. I scarfed that code,
      without changing any names, for a new project and I am running into a
      problem. Here is what I have:
      >
      The form definition:
      <form action="" method="post" enctype="multip art/form-data" name="History"
      target="_self">
      <input type="hidden" name="MAX_FILE_ SIZE" value="1250000" >
      >
      The file field:
      <input name="srcFile" type="file" id="srcFile">
      >
      The code for the copying:
      if (strlen(trim($_ FILES['srcFile']['name'])) 0) {
      $tmp_photo = "pic_" . $user . "_" . $_POST['petname'] . "_" .
      $_FILES['srcFile']['name'];
      echo "target=" . $tmp_photo . "<br>";
      echo "src=" . $_FILES['srcFile']['tmp_name'] . "<br>";
      $status = copy ($_FILES['srcFile']['tmp_name'], $tmp_photo);
      echo "status=" . $status . "<br>";
      ---- more processing follows ----
      >
      The result is:
      target=pic_shel donlg_coda_coda .jpg
      src=
      status=
      >
      In other words, it is not finding a value for
      $_FILES['srcFile']['tmp_name'], but it is finding the value for
      $_FILES['srcFile']['name'] (that value is coda.jpg and is nested a number
      of directories down on the C drive).
      >
      This worked fine before. Does anything leap out at anyone?
      >
      While I am here, how do you folks handle the time delay in processing the
      upload to avoid having impatient users? So far, all I am doing is putting a
      message before the hit the key to do the upload.
      >
      Shelly

      Comment

      • Shelly

        #4
        Re: Upload problem


        <petersprc@gmai l.comwrote in message
        news:1160349587 .512660.324520@ e3g2000cwe.goog legroups.com...
        Maybe $_FILES['srcFile']['error'] has an error code? I would also make
        sure you have write permissions to PHP's upload_tmp_dir
        (ini_get('uploa d_tmp_dir') or phpinfo() will tell you where it is).
        I did this and error came up as "2".

        The upload_tmp_dir came up as blank when I did it with theo ini_get. Also,
        it was "no value" with the phpinfo. Also, phpinfo gave "On" for
        file_uploads. What else should I be looking for?

        Shelly

        >
        As for long uploads, you could warn the user that the upload may take a
        while, or unhide a "Please Wait" image.
        >
        There are a couple techniques for a real upload progress indicator,
        some of which are shown here:
        >

        >

        >
        Shelly wrote:
        >I do what most programmers do -- we steal code from stuff we have written
        >src
        >before, or accept code from others that works, before we attempt to write
        >something altogether new.
        >>
        >On a previous project I wrote code to upload pictures and music from the
        >local drive to the server. It worked perfectly. I scarfed that code,
        >without changing any names, for a new project and I am running into a
        >problem. Here is what I have:
        >>
        >The form definition:
        ><form action="" method="post" enctype="multip art/form-data"
        >name="Histor y"
        >target="_self" >
        > <input type="hidden" name="MAX_FILE_ SIZE" value="1250000" >
        >>
        >The file field:
        ><input name="srcFile" type="file" id="srcFile">
        >>
        >The code for the copying:
        > if (strlen(trim($_ FILES['srcFile']['name'])) 0) {
        > $tmp_photo = "pic_" . $user . "_" . $_POST['petname'] . "_" .
        > $_FILES['srcFile']['name'];
        > echo "target=" . $tmp_photo . "<br>";
        > echo "src=" . $_FILES['srcFile']['tmp_name'] . "<br>";
        > $status = copy ($_FILES['srcFile']['tmp_name'], $tmp_photo);
        > echo "status=" . $status . "<br>";
        > ---- more processing follows ----
        >>
        >The result is:
        >target=pic_she ldonlg_coda_cod a.jpg
        >src=
        >status=
        >>
        >In other words, it is not finding a value for
        >$_FILES['srcFile']['tmp_name'], but it is finding the value for
        >$_FILES['srcFile']['name'] (that value is coda.jpg and is nested a
        >number
        >of directories down on the C drive).
        >>
        >This worked fine before. Does anything leap out at anyone?
        >>
        >While I am here, how do you folks handle the time delay in processing the
        >upload to avoid having impatient users? So far, all I am doing is
        >putting a
        >message before the hit the key to do the upload.
        >>
        >Shelly
        >

        Comment

        • Shelly

          #5
          Re: Upload problem

          I would like to thank you all for the help. It turned out that error=2 was
          the giveaway. I needed to increase the mas file size.

          Shelly


          Comment

          • petersprc@gmail.com

            #6
            Re: Upload problem

            Error code 2 means the uploaded file was bigger than the MAX_FILE_SIZE
            form directive, which in your case was about 1.2 MB.

            Upload error codes explained:



            On Oct 8, 11:02 pm, "Shelly" <sheldonlg.n... @asap-consult.comwrot e:
            <peters...@gmai l.comwrote in messagenews:116 0349587.512660. 324520@e3g2000c we.googlegroups .com...
            >
            Maybe $_FILES['srcFile']['error'] has an error code? I would also make
            sure you have write permissions to PHP's upload_tmp_dir
            (ini_get('uploa d_tmp_dir') or phpinfo() will tell you where it is).I did this and error came up as "2".
            >
            The upload_tmp_dir came up as blank when I did it with theo ini_get. Also,
            it was "no value" with the phpinfo. Also, phpinfo gave "On" for
            file_uploads. What else should I be looking for?
            >
            Shelly
            >
            >
            >
            As for long uploads, you could warn the user that the upload may take a
            while, or unhide a "Please Wait" image.
            >
            There are a couple techniques for a real upload progress indicator,
            some of which are shown here:
            >>>
            Shelly wrote:
            I do what most programmers do -- we steal code from stuff we have written
            src
            before, or accept code from others that works, before we attempt to write
            something altogether new.
            >
            On a previous project I wrote code to upload pictures and music from the
            local drive to the server. It worked perfectly. I scarfed that code,
            without changing any names, for a new project and I am running into a
            problem. Here is what I have:
            >
            The form definition:
            <form action="" method="post" enctype="multip art/form-data"
            name="History"
            target="_self">
            <input type="hidden" name="MAX_FILE_ SIZE" value="1250000" >
            >
            The file field:
            <input name="srcFile" type="file" id="srcFile">
            >
            The code for the copying:
            if (strlen(trim($_ FILES['srcFile']['name'])) 0) {
            $tmp_photo = "pic_" . $user . "_" . $_POST['petname'] . "_" .
            $_FILES['srcFile']['name'];
            echo "target=" . $tmp_photo . "<br>";
            echo "src=" . $_FILES['srcFile']['tmp_name'] . "<br>";
            $status = copy ($_FILES['srcFile']['tmp_name'], $tmp_photo);
            echo "status=" . $status . "<br>";
            ---- more processing follows ----
            >
            The result is:
            target=pic_shel donlg_coda_coda .jpg
            src=
            status=
            >
            In other words, it is not finding a value for
            $_FILES['srcFile']['tmp_name'], but it is finding the value for
            $_FILES['srcFile']['name'] (that value is coda.jpg and is nested a
            number
            of directories down on the C drive).
            >
            This worked fine before. Does anything leap out at anyone?
            >
            While I am here, how do you folks handle the time delay in processing the
            upload to avoid having impatient users? So far, all I am doing is
            putting a
            message before the hit the key to do the upload.
            >
            Shelly

            Comment

            • Shelly

              #7
              Re: Upload problem


              <petersprc@gmai l.comwrote in message
              news:1160363975 .725865.81000@h 48g2000cwc.goog legroups.com...
              Error code 2 means the uploaded file was bigger than the MAX_FILE_SIZE
              form directive, which in your case was about 1.2 MB.
              Yes, that was it. In typing this post I automatically put in what I had
              inteded originally, but actually I had it incorrectly as 125000 in my code.
              When I looked at what error code 2 was I went back and noticed my typo in my
              code. Thank you again.

              Shelly
              >
              Upload error codes explained:
              >

              >
              On Oct 8, 11:02 pm, "Shelly" <sheldonlg.n... @asap-consult.comwrot e:
              ><peters...@gma il.comwrote in
              >messagenews:11 60349587.512660 .324520@e3g2000 cwe.googlegroup s.com...
              >>
              Maybe $_FILES['srcFile']['error'] has an error code? I would also make
              sure you have write permissions to PHP's upload_tmp_dir
              (ini_get('uploa d_tmp_dir') or phpinfo() will tell you where it is).I
              did this and error came up as "2".
              >>
              >The upload_tmp_dir came up as blank when I did it with theo ini_get.
              >Also,
              >it was "no value" with the phpinfo. Also, phpinfo gave "On" for
              >file_uploads . What else should I be looking for?
              >>
              >Shelly
              >>
              >>
              >>
              As for long uploads, you could warn the user that the upload may take a
              while, or unhide a "Please Wait" image.
              >>
              There are a couple techniques for a real upload progress indicator,
              some of which are shown here:
              >>>>>>
              Shelly wrote:
              >I do what most programmers do -- we steal code from stuff we have
              >written
              >src
              >before, or accept code from others that works, before we attempt to
              >write
              >something altogether new.
              >>
              >On a previous project I wrote code to upload pictures and music from
              >the
              >local drive to the server. It worked perfectly. I scarfed that code,
              >without changing any names, for a new project and I am running into a
              >problem. Here is what I have:
              >>
              >The form definition:
              ><form action="" method="post" enctype="multip art/form-data"
              >name="Histor y"
              >target="_self" >
              > <input type="hidden" name="MAX_FILE_ SIZE" value="1250000" >
              >>
              >The file field:
              ><input name="srcFile" type="file" id="srcFile">
              >>
              >The code for the copying:
              > if (strlen(trim($_ FILES['srcFile']['name'])) 0) {
              > $tmp_photo = "pic_" . $user . "_" . $_POST['petname'] . "_" .
              > $_FILES['srcFile']['name'];
              > echo "target=" . $tmp_photo . "<br>";
              > echo "src=" . $_FILES['srcFile']['tmp_name'] . "<br>";
              > $status = copy ($_FILES['srcFile']['tmp_name'], $tmp_photo);
              > echo "status=" . $status . "<br>";
              > ---- more processing follows ----
              >>
              >The result is:
              >target=pic_she ldonlg_coda_cod a.jpg
              >src=
              >status=
              >>
              >In other words, it is not finding a value for
              >$_FILES['srcFile']['tmp_name'], but it is finding the value for
              >$_FILES['srcFile']['name'] (that value is coda.jpg and is nested a
              >number
              >of directories down on the C drive).
              >>
              >This worked fine before. Does anything leap out at anyone?
              >>
              >While I am here, how do you folks handle the time delay in processing
              >the
              >upload to avoid having impatient users? So far, all I am doing is
              >putting a
              >message before the hit the key to do the upload.
              >>
              >Shelly
              >

              Comment

              • .:[ ikciu ]:.

                #8
                Re: Upload problem

                Hmm Shelly <sheldonlg.news @asap-consult.comwrot e:
                <form action="" method="post" enctype="multip art/form-data"
                name="History" target="_self">
                It looks like xhtml - if yes dont use enctype for from
                if (strlen(trim($_ FILES['srcFile']['name'])) 0) {

                you should to check $_FILES['srcFile']['error']

                --
                ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
                Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

                2be || !2be $this =mysql_query();


                Comment

                Working...