473,382 Members | 1,622 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,382 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 3308
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.