PHP and upload

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes

    #1

    PHP and upload

    I have a strange problem when uploading a PDF document to a web-server. When
    I try this to a web-server running Apache 2 on a FC 4, it fails. Firefox
    says that the document contain no data.
    If I upload it to a different web-server running RH 7.3 (an internal
    test-webserver), it works OK.

    The PDF document is created by OpenOffice 2.0 from a MS Word document. I
    have also had it converted to PDF in MS Word that could create PDF
    documents. Still the same error. I am able to view the PDF document on a
    Windows machine, but not on my FC 4. Ghostscript crash.

    The HTML code for the form is:
    <FORM ENCTYPE=multipa rt/form-data ACTION=upload.p hp METHOD=post><PR E>
    <INPUT TYPE=hidden NAME=max_file_s ize VALUE=4096000>
    Title: <INPUT TYPE=text SIZE=24 NAME=title File: <INPUT TYPE=file
    NAME=upfile>
    <BR><INPUT TYPE=submit VALUE="Load"></PRE></FORM>

    When I look at the access_log file at the web-server, the PHP script in the
    ACTION field in the FORM is not called. So the error happens before the
    script is called.

    I have on question about the upload script: Where is the content of
    $_FILES['upfile']['type'] set? I assume it is the web-server that sets this
    before calling the action script?
    Could the cause of the error be that the web-server is not able to determin
    the type of the file?

    I have tried with other PDF documents, also created from MS Word and
    converted to PDF using OpenOffice 2.0. And it workes OK. So it seems like
    there is somehting in the file that cause the problems.

    --
    Jørn Dahl-Stamnes

  • Erwin Moller

    #2
    Re: PHP and upload

    Jørn Dahl-Stamnes wrote:

    Hi,
    I have a strange problem when uploading a PDF document to a web-server.
    When I try this to a web-server running Apache 2 on a FC 4, it fails.
    Firefox says that the document contain no data.
    That means nothing.
    You should check what PHP is doing. Clearly you have some problem handling
    uploaded files.
    A blind guess would be a permissionprobl em, but you should debug this
    yourself.

    If I upload it to a different web-server running RH 7.3 (an internal
    test-webserver), it works OK.
    Probably the relevant directories on the testserver are open for PHP to
    write in, and not on your FC4 machine.
    >
    The PDF document is created by OpenOffice 2.0 from a MS Word document. I
    have also had it converted to PDF in MS Word that could create PDF
    documents. Still the same error. I am able to view the PDF document on a
    Windows machine, but not on my FC 4. Ghostscript crash.
    This is not relevant.
    A file is a file, even if you upload it.
    If things are programmed OK, the content or origin of the file matters not.
    >
    The HTML code for the form is:
    <FORM ENCTYPE=multipa rt/form-data ACTION=upload.p hp METHOD=post><PR E>
    <INPUT TYPE=hidden NAME=max_file_s ize VALUE=4096000>
    Title: <INPUT TYPE=text SIZE=24 NAME=title File: <INPUT TYPE=file
    NAME=upfile>
    <BR><INPUT TYPE=submit VALUE="Load"></PRE></FORM>
    >
    Look ok, except for the missing ""
    Try this:
    <FORM ENCTYPE="multip art/form-data" ACTION="upload. php" METHOD="post">

    Most browser autofix broken HTML, so I do not expect this is your problem,
    but better to write things down according to the specs (RFC).
    When I look at the access_log file at the web-server, the PHP script in
    the ACTION field in the FORM is not called. So the error happens before
    the script is called.
    Maybe you didn't set up PHP to handle uploads right?
    Check you php.ini

    Look for the file-upload department:

    ;;;;;;;;;;;;;;; ;
    ; File Uploads ;
    ;;;;;;;;;;;;;;; ;

    ; Whether to allow HTTP file uploads.
    file_uploads = On

    ; Temporary directory for HTTP uploaded files (will use system default if
    not
    ; specified).
    ;upload_tmp_dir =

    ; Maximum allowed size for uploaded files.
    upload_max_file size = 2M


    Does your settings look anything like this?
    Pay extra attention to the upload_tmp_dir.
    If you ommit it, a default temp-dir will be used.
    Bottomline is that PHP needs rights to write in that directory.

    Find out which user PHP runs as on your FC4 machine. (Could be anything from
    php, apache, nobody, www-data, or who knows what)

    >
    I have on question about the upload script: Where is the content of
    $_FILES['upfile']['type'] set? I assume it is the web-server that sets
    this before calling the action script?
    'type' is not really important, it is set by the browser.

    From the fine manual:


    $_FILES['userfile']['type']

    The mime type of the file, if the browser provided this information. An
    example would be "image/gif". This mime type is however not checked on the
    PHP side and therefore don't take its value for granted.
    Could the cause of the error be that the web-server is not able to
    determin the type of the file?
    I think not.
    >
    I have tried with other PDF documents, also created from MS Word and
    converted to PDF using OpenOffice 2.0. And it workes OK. So it seems like
    there is somehting in the file that cause the problems.
    >
    My guess if you cannot upload a thing, be it pdf or gif or png.

    Start debugging.

    So 3 thing to do:
    1) Check your php.ini settings if they make sense.
    2) Check if the uploaddir is indeed writable by the user that runs PHP as.
    3) debug the app itself.
    a good start is putting this above your script:
    echo "<pre>";
    print_r($_FILES );
    echo "</pre>";

    Good luck.

    Regards,
    Erwin Moller

    Comment

    • =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes

      #3
      Re: PHP and upload

      Erwin Moller wrote:
      Jørn Dahl-Stamnes wrote:
      >
      Hi,
      >
      >I have a strange problem when uploading a PDF document to a web-server.
      >When I try this to a web-server running Apache 2 on a FC 4, it fails.
      >Firefox says that the document contain no data.
      >
      That means nothing.
      You should check what PHP is doing. Clearly you have some problem handling
      uploaded files.
      A blind guess would be a permissionprobl em, but you should debug this
      yourself.
      I can upload all kinds of documents, images, excel sheets etc. But not this
      particular file. I cannot see what PHP is doing, since the upload script is
      never called before the error occurs.
      >If I upload it to a different web-server running RH 7.3 (an internal
      >test-webserver), it works OK.
      >
      Probably the relevant directories on the testserver are open for PHP to
      write in, and not on your FC4 machine.
      No, I have checked this. I am able to upload other files without problems.
      >The PDF document is created by OpenOffice 2.0 from a MS Word document. I
      >have also had it converted to PDF in MS Word that could create PDF
      >documents. Still the same error. I am able to view the PDF document on a
      >Windows machine, but not on my FC 4. Ghostscript crash.
      >
      This is not relevant.
      A file is a file, even if you upload it.
      That is what I think to. But why does it complain on this one file, while
      all other files is uploaded without any problems at all? I have tried 20
      different files (JPEG, MS Words, Excel, other PDF files) with success.
      If things are programmed OK, the content or origin of the file matters
      not.
      Since I am able to upload 20 other files, the code IS working.

      * I have checked the php.ini files, and it seems to be OK.
      * The upload directory is writeable since I can upload other files.
      * print_r ($_FILES) will not work, since the action script is never called
      when the error occurs.
      Good luck.
      thanks... I'll need it since there is no good answer why this happens.

      --
      Jørn Dahl-Stamnes

      Comment

      • Erwin Moller

        #4
        Re: PHP and upload

        Jørn Dahl-Stamnes wrote:
        Erwin Moller wrote:
        >
        >Jørn Dahl-Stamnes wrote:
        >>
        >Hi,
        >>
        >>I have a strange problem when uploading a PDF document to a web-server.
        >>When I try this to a web-server running Apache 2 on a FC 4, it fails.
        >>Firefox says that the document contain no data.
        >>
        >That means nothing.
        >You should check what PHP is doing. Clearly you have some problem
        >handling uploaded files.
        >A blind guess would be a permissionprobl em, but you should debug this
        >yourself.
        >
        I can upload all kinds of documents, images, excel sheets etc. But not
        this particular file. I cannot see what PHP is doing, since the upload
        script is never called before the error occurs.
        >
        >>If I upload it to a different web-server running RH 7.3 (an internal
        >>test-webserver), it works OK.
        >>
        >Probably the relevant directories on the testserver are open for PHP to
        >write in, and not on your FC4 machine.
        >
        No, I have checked this. I am able to upload other files without problems.
        >
        >>The PDF document is created by OpenOffice 2.0 from a MS Word document. I
        >>have also had it converted to PDF in MS Word that could create PDF
        >>documents. Still the same error. I am able to view the PDF document on a
        >>Windows machine, but not on my FC 4. Ghostscript crash.
        >>
        >This is not relevant.
        >A file is a file, even if you upload it.
        >
        That is what I think to. But why does it complain on this one file, while
        all other files is uploaded without any problems at all? I have tried 20
        different files (JPEG, MS Words, Excel, other PDF files) with success.
        >
        >If things are programmed OK, the content or origin of the file matters
        >not.
        >
        Since I am able to upload 20 other files, the code IS working.
        >
        * I have checked the php.ini files, and it seems to be OK.
        * The upload directory is writeable since I can upload other files.
        * print_r ($_FILES) will not work, since the action script is never called
        when the error occurs.
        >
        >Good luck.
        >
        thanks... I'll need it since there is no good answer why this happens.
        >
        Hi again,

        Well that is strange indeed. I blindly assumed the code was failing on all
        uploads, but you claim it only fails on pdf. Sorry, my bad. :-)

        Summarizing:
        1) Your upload script works fine for all files except (some) pdf.
        2) In your log you can see the call to the upload-script for all succesfull
        uploads, but NOT when uploading this pdf. You find NO record in apachelogs
        at all.

        If this is the situation, my guess would be that apache2 is somehow screwing
        up before php gets involved.

        Can you check your apache errorfiles?
        Anything out of the ordinary?

        Regards,
        Erwin Moller

        Comment

        • =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes

          #5
          Re: PHP and upload

          Erwin Moller wrote:
          Hi again,
          >
          Well that is strange indeed. I blindly assumed the code was failing on all
          uploads, but you claim it only fails on pdf. Sorry, my bad. :-)
          Or I did not explain my self good enough...
          Summarizing:
          1) Your upload script works fine for all files except (some) pdf.
          Yes, and make it ONE pdf file.
          2) In your log you can see the call to the upload-script for all
          succesfull uploads, but NOT when uploading this pdf. You find NO record in
          apachelogs at all.
          That is right. No entry in the log that indicate that the upload script has
          been called when I get the error message.

          With an older version of Firefox unde FC4 I get "Alert: Document contain no
          data", while I with the latest Firefox under Windows 2000 get a message
          that say "The connection to the server was reset while the page was
          loading". And I get a different message with IE under W2k.
          If this is the situation, my guess would be that apache2 is somehow
          screwing up before php gets involved.
          >
          Can you check your apache errorfiles?
          Anything out of the ordinary?
          No errors in the error_log file.

          I also tried:
          * Open the original Word document on my W2k machine and save it as pure txt
          * Start word and insert the txt file and do a simple format
          * Save the document to a new filename.
          * On FC4: Convert the new document file in OpenOffice and convert it to PDF
          * Upload the PDF file.

          This works OK. But FC4 is not able to view the PDF file.

          I also had a friend to convert the first Word document to PDF on a Windows
          platform (since I don't have the proper software under Windows). This one
          also fails, but now I can view the PDF file on FC4 without problems.

          --
          Jørn Dahl-Stamnes

          Comment

          • Erwin Moller

            #6
            Re: PHP and upload

            Jørn Dahl-Stamnes wrote:
            Erwin Moller wrote:
            >Hi again,
            >>
            >Well that is strange indeed. I blindly assumed the code was failing on
            >all
            >uploads, but you claim it only fails on pdf. Sorry, my bad. :-)
            >
            Or I did not explain my self good enough...
            >
            >Summarizing:
            >1) Your upload script works fine for all files except (some) pdf.
            >
            Yes, and make it ONE pdf file.
            >
            >2) In your log you can see the call to the upload-script for all
            >succesfull uploads, but NOT when uploading this pdf. You find NO record
            >in apachelogs at all.
            >
            That is right. No entry in the log that indicate that the upload script
            has been called when I get the error message.
            >
            With an older version of Firefox unde FC4 I get "Alert: Document contain
            no data", while I with the latest Firefox under Windows 2000 get a message
            that say "The connection to the server was reset while the page was
            loading". And I get a different message with IE under W2k.
            >
            >If this is the situation, my guess would be that apache2 is somehow
            >screwing up before php gets involved.
            >>
            >Can you check your apache errorfiles?
            >Anything out of the ordinary?
            >
            No errors in the error_log file.
            >
            I also tried:
            * Open the original Word document on my W2k machine and save it as pure
            txt * Start word and insert the txt file and do a simple format
            * Save the document to a new filename.
            * On FC4: Convert the new document file in OpenOffice and convert it to
            PDF * Upload the PDF file.
            >
            This works OK. But FC4 is not able to view the PDF file.
            >
            I also had a friend to convert the first Word document to PDF on a Windows
            platform (since I don't have the proper software under Windows). This one
            also fails, but now I can view the PDF file on FC4 without problems.
            >
            Hi,

            Beats me. :-/
            What bothers me most is the fact apache is not logging the call to the
            uploadscript.
            I think I would focus on that first before worrying about conversions via
            word/open office/etc.
            I looks like the upload is failing at a very early stage...
            Some currupt headers or something that confuses Apache enough to refuse to
            log it.
            I never have been in that situation before.

            Maybe you could repost your problem in an apache newsgroup if noby in here
            comes up with ideas.

            Good luck.

            Regards,
            Erwin Moller

            Comment

            • =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes

              #7
              Re: PHP and upload

              Erwin Moller wrote:
              Hi,
              >
              Beats me. :-/
              What bothers me most is the fact apache is not logging the call to the
              uploadscript.
              I think I would focus on that first before worrying about conversions via
              word/open office/etc.
              I looks like the upload is failing at a very early stage...
              I does log the upload script if I add another file (word, jpeg, pdf).
              Some currupt headers or something that confuses Apache enough to refuse to
              log it.
              I never have been in that situation before.
              >
              Maybe you could repost your problem in an apache newsgroup if noby in here
              comes up with ideas.
              I consider that.
              Good luck.
              Thanks.

              --
              Jørn Dahl-Stamnes

              Comment

              Working...