473,242 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

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=multipart/form-data ACTION=upload.php METHOD=post><PRE>
<INPUT TYPE=hidden NAME=max_file_size 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
http://www.dahl-stamnes.net/dahls/
Jan 30 '07 #1
6 3301
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 permissionproblem, 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=multipart/form-data ACTION=upload.php METHOD=post><PRE>
<INPUT TYPE=hidden NAME=max_file_size 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="multipart/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_filesize = 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:
http://nl2.php.net/manual/en/features.file-upload.php

$_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
Jan 30 '07 #2
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 permissionproblem, 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
http://www.dahl-stamnes.net/dahls/
Jan 30 '07 #3
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 permissionproblem, 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
Jan 30 '07 #4
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
http://www.dahl-stamnes.net/dahls/
Jan 30 '07 #5
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
Jan 30 '07 #6
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
http://www.dahl-stamnes.net/dahls/
Jan 30 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
2
by: Sean Dotson | last post by:
I have a form that passes variables to an asp file and then uploads a file. For some reason the request.form is not getting the info from the form. It's returning blanks. Any insight would be...
0
by: SEMIH DEMIR | last post by:
Sitelerden birinde verilen yabancý kaynakli bir scriptti duzenledim yanlýz birseyin içinden bir turlu cýkamadým iþin aslý ilk defa persistin upload componentini kullanacam yanlýz suanki haliyle...
1
by: Alex | last post by:
I am having issues with a script to upload files from a client to a webserver. The problem is not with the actual upload but with where it uploads. The whole process is supposed to create a...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.