473,770 Members | 7,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I enable upload a pdf file with php ?

290 Contributor
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 6123
Atli
5,058 Recognized Expert Expert
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 "applicatio n/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_f ile function should take care of the rest.
May 15 '09 #2
jeddiki
290 Contributor
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
11763
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 table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
2
2458
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 appreciated.... Here is the asp file <HTML> <HEAD> <TITLE>File Upload Results</TITLE>
1
1627
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 /home/jbsmedia/public_html/ftp.php on line 352. when i download files, when i upload i get Upload failed! Can't create temp file?. as far as i fuigured i set my ftp file folder cmod 777. then must have to do somethin to the htaccess file. my host...
9
3838
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 site for a small club I belong to and one of the features I would like to include is the ability to allow users to upload image files. unfortunately the servers web root www folder only allows READ and EXECUTE permissions, which makes it...
7
3190
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" name="file_1" size=46 /><input type=submit /> so, after adding a few files, the input fields look like this:
9
20899
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 rapidshare news : http://images.rapidshare.com/software/rsapi.pl If you test it you will see that you can upload one file at time. I try to modify it in that way that script can read a text file with the names of the files i want to...
21
34438
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 obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
2
7651
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 don't have any luck is to do a form validation. This script requires the files: db-file-to-disk.asp and _upload.asp. There is a DESCRIPTION field in the db-file-to-disk.asp file, what I want to do is the user has to field out this fied before...
1
4884
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 program,which can upload many file in folder.problem is,am unable to save my file name in to database.because i used same name for all input file type as file. i dont know get name of file.below i presented my coding for ur view.fed up with my coding..pls...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7416
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.