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