473,405 Members | 2,338 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,405 software developers and data experts.

Can I enable upload a pdf file with php ?

290 100+
Hello,

Hopefully I can do this with php

I want to allow my clients to upload their pdf or video files to my server without giving them ftp login details.

Lets look at PDF's first:

This must be similar code to uploading an image - same thing really - just the checking must be different I guess?

This is what I have for the form:
I think that I have specified 10Mb and the max ( maybe that's a bit low ? )

Expand|Select|Wrap|Line Numbers
  1. /*
  2. *  upload_fm.php
  3. *
  4. */
  5. <form name="main_fm" enctype ="multipart/form-data" action ='upload_check.php' method = 'POST'>
  6. <input type = 'hidden' name='upld' value="on">
  7. <input type="hidden" name ="MAX FILE SIZE" value="10000000">
  8. <b>Your PDF:</b><br>
  9. <input type="file" size="50" id = "u1" name="upLoad">
  10. <input type="submit" value="Upload PDF">
  11. </form> 
  12.  
So far I have this to check the pdf but I have no idea how to proceed from here

I guess that I need to check somehow that it is a PDF and not some horrible virus program!

Then I need to move the file to a directory so that it can be access by another script to allow downloading.

Let's say that I want to put it on /MyPDF directory so the path will be
/MyPDF/nameofPDF.pdf

Would really appreciate any help

Expand|Select|Wrap|Line Numbers
  1. /*
  2. *   upload_check.php
  3. *
  4. */
  5.  
  6. $N_pdf  =    $_FILES['upLoad']["name"];
  7.  
  8.  
  9. // possible PHP upload errors 
  10. $errors = array(1 => 'php.ini max file size exceeded', 
  11.                 2 => 'html form max file size exceeded', 
  12.                 3 => 'file upload was only partial', 
  13.                 4 => 'no file was attached'); 
  14.  
  15. if ($_FILES['upLoad']['error'] != 0) { 
  16.         $message1 = "PDF file did not successfully upload" ; 
  17.         $message2 =  "Error: ".$errors[$_FILES['upLoad']['error']]; 
  18.         require_once ("upload_fm.php"); 
  19.         exit(); 
  20. }  // endif 

Thanks for any input
May 15 '09 #1
2 6093
Atli
5,058 Expert 4TB
Hi.

Yes, the process of uploading a PDF is pretty much the same as uploading an Image.
The only difference is the validation process.

There are a few things you can check to see if it is in fact a PDF file, but there is never a way to be 100% sure.
The best defence against harmful files is to put them somewhere they can't be accessed by outsiders. (Outside the web-root)

Personally, to validate a PDF file, I would consider these steps sufficient:
  1. Make sure the mime type is "application/pdf"
  2. Make sure the file extension is .pdf
  3. Make sure the first 5 bytes of the file read "%PDF-" (As per the standard)
This should at least prevent accidental uploads of invalid files, and attempts to upload non-pdf files.

If all that checks out, the move_uploaded_file function should take care of the rest.
May 15 '09 #2
jeddiki
290 100+
Thanks very much for your advice,
I think I can move forward on this now :)
May 16 '09 #3

Sign in to post your reply or Sign up for a free account.

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...
1
by: sellbellz | last post by:
I am having problems with a ftp to http php scrip: Warning: ftp_get(): open_basedir restriction in effect. File(/ftp_login.html.600490715) is not within the allowed path(s): (/home:/tmp:/usr) in...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.