473,396 Members | 1,683 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,396 software developers and data experts.

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_quotes_runtime(0);
$pdfname="d".$job."-".$select.".pdf";
copy($filename, addslashes("/home/images/$pdfname"));
unlink($filename);
header("Location: admin.php?ID=$ID&add_design=Y&job=$storm");

I added the set_magic_quotes_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.
Jul 17 '05 #1
4 4455
"Adrian Hill" <no****@bo.selecta.com> wrote in message
news:c1**********@newsreaderg1.core.theplanet.net. ..
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_quotes_runtime(0);
$pdfname="d".$job."-".$select.".pdf";
copy($filename, addslashes("/home/images/$pdfname"));
unlink($filename);
header("Location: admin.php?ID=$ID&add_design=Y&job=$storm");

I added the set_magic_quotes_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.


You have to specify binary rather than ascii
Jul 17 '05 #2
Many thanks for your response,
You have to specify binary rather than ascii


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.
Jul 17 '05 #3
Adrian Hill wrote:
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_quotes_runtime(0);
$pdfname="d".$job."-".$select.".pdf";
copy($filename, addslashes("/home/images/$pdfname"));
unlink($filename);
header("Location: admin.php?ID=$ID&add_design=Y&job=$storm");

I added the set_magic_quotes_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.


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_file()

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
Jul 17 '05 #4
I don't know if slashes are added to uploaded file. If they are, then your
call to set_magic_quotes_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" <no****@bo.selecta.com> napisal w wiadomosci
news:c1**********@newsreaderg1.core.theplanet.net. ..
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_quotes_runtime(0);
$pdfname="d".$job."-".$select.".pdf";
copy($filename, addslashes("/home/images/$pdfname"));
unlink($filename);
header("Location: admin.php?ID=$ID&add_design=Y&job=$storm");

I added the set_magic_quotes_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.

Jul 17 '05 #5

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
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.