PDF upload...

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

    #1

    PDF upload...

    Hi all,

    I can upload plaintext files to the server fine, but when I try to
    upload a pdf, it tells me that the file is damaged and could not be
    repaired. The file is uploaded to the correct place on the server, but
    is significantly larger (almost twice as large) as the original file
    before upload.

    Viewing the uploaded files in a web page (download.php) or accessing
    the files directly gives the same message, so I believe the problem is
    happening during the upload process.

    Code snippet follows...

    set_magic_quote s_runtime(0);
    $pdfname="d".$j ob."-".$select.".pdf ";
    copy($filename, addslashes("/home/images/$pdfname"));
    unlink($filenam e);
    header("Locatio n: admin.php?ID=$I D&add_design=Y& job=$storm");

    I added the set_magic_quote s_runtime(0) and addslashes() function
    calls. Permissions are set to 755 in directory /home/images/

    Any advice on this would be much appreciated,

    Cheers,


    Ade.


  • Van Johnson

    #2
    Re: PDF upload...

    "Adrian Hill" <nospam@bo.sele cta.com> wrote in message
    news:c1d3p4$h7l $1@newsreaderg1 .core.theplanet .net...[color=blue]
    > Hi all,
    >
    > I can upload plaintext files to the server fine, but when I try to
    > upload a pdf, it tells me that the file is damaged and could not be
    > repaired. The file is uploaded to the correct place on the server, but
    > is significantly larger (almost twice as large) as the original file
    > before upload.
    >
    > Viewing the uploaded files in a web page (download.php) or accessing
    > the files directly gives the same message, so I believe the problem is
    > happening during the upload process.
    >
    > Code snippet follows...
    >
    > set_magic_quote s_runtime(0);
    > $pdfname="d".$j ob."-".$select.".pdf ";
    > copy($filename, addslashes("/home/images/$pdfname"));
    > unlink($filenam e);
    > header("Locatio n: admin.php?ID=$I D&add_design=Y& job=$storm");
    >
    > I added the set_magic_quote s_runtime(0) and addslashes() function
    > calls. Permissions are set to 755 in directory /home/images/
    >
    > Any advice on this would be much appreciated,
    >
    > Cheers,
    >
    >
    > Ade.
    >
    >[/color]

    You have to specify binary rather than ascii


    Comment

    • Adrian Hill

      #3
      Re: PDF upload...

      Many thanks for your response,
      [color=blue]
      > You have to specify binary rather than ascii[/color]

      Where in the code should I do this exactly? Could you be a little more
      specific please?

      I made sure the file is uploaded using a multipart request in the form on
      the preceding page. Is that what you are getting at?

      Are you implying that you have to pass it though a different function, like
      open( $filename, 'bf' ); Doesn't the 'bf' say it's a binary file in that
      case?

      I'm sorry, I'm not finding the advice that clear. While I have experience
      programming using jsp, I havn't done any php hacking for a year or so and am
      a little rusty.

      Thanks again,


      Ade.


      Comment

      • Reply Via Newsgroup

        #4
        Re: PDF upload...

        Adrian Hill wrote:
        [color=blue]
        > Hi all,
        >
        > I can upload plaintext files to the server fine, but when I try to
        > upload a pdf, it tells me that the file is damaged and could not be
        > repaired. The file is uploaded to the correct place on the server, but
        > is significantly larger (almost twice as large) as the original file
        > before upload.
        >
        > Viewing the uploaded files in a web page (download.php) or accessing
        > the files directly gives the same message, so I believe the problem is
        > happening during the upload process.
        >
        > Code snippet follows...
        >
        > set_magic_quote s_runtime(0);
        > $pdfname="d".$j ob."-".$select.".pdf ";
        > copy($filename, addslashes("/home/images/$pdfname"));
        > unlink($filenam e);
        > header("Locatio n: admin.php?ID=$I D&add_design=Y& job=$storm");
        >
        > I added the set_magic_quote s_runtime(0) and addslashes() function
        > calls. Permissions are set to 755 in directory /home/images/
        >
        > Any advice on this would be much appreciated,
        >
        > Cheers,
        >
        >
        > Ade.
        >
        >[/color]

        I'm pulling at straws here - But I notice that you're copying $filename
        to /home/images/$pdfname

        Is $filename the file that was uploaded?

        If so, why are you using copy()? You should be using move_uploaded_f ile()

        Secondly, for your testing purpsoes, I'd suggest you have the file
        copied to $_SERVER[DOCUMENT_ROOT]/$pdfname - You don't need to
        addslashes() - I have not read any recommendation to do this, and I
        don't do it with my uploads.

        If you still have problems, then try and 'put' the file on the server
        with ftp - Then, ftp again, and 'get' it back to your client and see if
        you can still read/view it.

        Why?

        I suggest this because for some strange reason, my previous SuSE 7.1
        server had problems with some files - specifically gifs and pdf files
        and I was never able to find the cause - I first found the problem with
        PHP uploads - After days and days of scratching my head, I used FTP and
        found it had replicated the problem therefore removing PHP as being the
        cause.

        I found one other person in this ng that had a similar problem.
        Basically, I was able to ftp 'put' the full contents of my laptop
        windows documents drive on to my server as a backup - When I tried to
        restore everything, I found that pdf and gif's were unreadable - any
        other type of file, binary or ascii was fine though - thus, jpgs, wmv,
        mov, avi, mp3, txt, html were all fine - But pdf's and gifs were
        corrupted - The problem was not related to the transfer mode as I ftp
        'put' everything up at once - and I restored everything at once (as a
        test).

        Again, if you encounter the same problem as I did, I do not know the
        solution - However at very least it should help you clarify if it is
        problem unique to PHP, or not...

        Hope some of the above helps...

        randelld

        Comment

        • Chung Leong

          #5
          Re: PDF upload...

          I don't know if slashes are added to uploaded file. If they are, then your
          call to set_magic_quote s_runtime() would have no effect, since the file is
          already saved. Try uploading a text file with slashes and see what happens.

          Uzytkownik "Adrian Hill" <nospam@bo.sele cta.com> napisal w wiadomosci
          news:c1d3p4$h7l $1@newsreaderg1 .core.theplanet .net...[color=blue]
          > Hi all,
          >
          > I can upload plaintext files to the server fine, but when I try to
          > upload a pdf, it tells me that the file is damaged and could not be
          > repaired. The file is uploaded to the correct place on the server, but
          > is significantly larger (almost twice as large) as the original file
          > before upload.
          >
          > Viewing the uploaded files in a web page (download.php) or accessing
          > the files directly gives the same message, so I believe the problem is
          > happening during the upload process.
          >
          > Code snippet follows...
          >
          > set_magic_quote s_runtime(0);
          > $pdfname="d".$j ob."-".$select.".pdf ";
          > copy($filename, addslashes("/home/images/$pdfname"));
          > unlink($filenam e);
          > header("Locatio n: admin.php?ID=$I D&add_design=Y& job=$storm");
          >
          > I added the set_magic_quote s_runtime(0) and addslashes() function
          > calls. Permissions are set to 755 in directory /home/images/
          >
          > Any advice on this would be much appreciated,
          >
          > Cheers,
          >
          >
          > Ade.
          >
          >[/color]


          Comment

          Working...