Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

uploading pdf's only

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

uploading pdf's only

Postby ravi951 » Fri Jul 08, 2011 10:36 pm

HI all,
I need php code to upload only pdf files.Other than pdf it should reject .I have done in this way but it is not executing.It is uploading all type of files.

<?php
if($_FILES['file']['type']="application/pdf")
{
if($_POST[upload] =="1")
{
$to="uploads/".$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'],$to);
echo "uploaded";
}
else "it is not a pdf";
}
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="upload" value="1">
<input type="file" name="file">
<input type="submit" value="upload">
</form>

Kindly tell me what to modify......
ravi951
New php-forum User
New php-forum User
 
Posts: 26
Joined: Sat Jun 25, 2011 4:40 am

Re: uploading pdf's only

Postby rjtengco » Fri Jul 08, 2011 11:57 pm

<?php
if($_FILES['file']['type']=="application/pdf")
{
if($_POST[upload] =="1")
{
$to="uploads/".$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'],$to);
echo "uploaded";
}
else "it is not a pdf";
}
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="upload" value="1">
<input type="file" name="file">
<input type="submit" value="upload">
</form>

try this code; see your = operators at the first if condition it should be == tnx
rjtengco
New php-forum User
New php-forum User
 
Posts: 25
Joined: Fri Jul 08, 2011 10:59 pm

Re: uploading pdf's only

Postby rjtengco » Sat Jul 09, 2011 12:15 am

<?php
if($_FILES['file']['type']=="application/pdf"){
if($_POST[upload] =="1"){
$to="uploads/".$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'],$to);
echo "uploaded";
}
}else{
echo "it is not a pdf";
};
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="upload" value="1">
<input type="file" name="file">
<input type="submit" value="upload">
</form>

hi ravi951, here is the much cleaner code.
rjtengco
New php-forum User
New php-forum User
 
Posts: 25
Joined: Fri Jul 08, 2011 10:59 pm

Re: uploading pdf's only

Postby ravi951 » Sat Jul 09, 2011 12:34 am

hi dude the other files r not uploading but it is not displaying the message"it is not a pdf file".
i have given echo message.
It should display me the message other than pdf's if we are trying to upload.
ravi951
New php-forum User
New php-forum User
 
Posts: 26
Joined: Sat Jun 25, 2011 4:40 am

Re: uploading pdf's only

Postby rjtengco » Sat Jul 09, 2011 12:37 am

<?php
if($_FILES['file']['type']=="application/pdf"){
if($_POST[upload] =="1"){
$to="uploads/".$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'],$to);
echo "uploaded";
}
}else{
echo "it is not a pdf";
};
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="upload" value="1">
<input type="file" name="file">
<input type="submit" value="upload">
</form>

try this code this should work
rjtengco
New php-forum User
New php-forum User
 
Posts: 25
Joined: Fri Jul 08, 2011 10:59 pm

Re: uploading pdf's only

Postby ravi951 » Sat Jul 09, 2011 12:58 am

no dude it is not working...check once.........
It is displaying message "it is not pdf" before we are trying to upload
ravi951
New php-forum User
New php-forum User
 
Posts: 26
Joined: Sat Jun 25, 2011 4:40 am

Re: uploading pdf's only

Postby rjtengco » Sat Jul 09, 2011 1:08 am

<?php
$message = "";

if($_POST[upload] =="1"){
if($_FILES['file']['type']=="application/pdf"){
$to="uploads/".$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'],$to);
$message = "upload";
}else{
$message = "it is not a pdf";
}
};
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="upload" value="1">
<input type="file" name="file">
<input type="submit" value="upload">
</form>
<?php
echo $message;

?>

ok i see the problem here is the revised one.
rjtengco
New php-forum User
New php-forum User
 
Posts: 25
Joined: Fri Jul 08, 2011 10:59 pm

Re: uploading pdf's only

Postby ravi951 » Sat Jul 09, 2011 1:21 am

dude i got it...we need to check with isset function.....below is the code working perfectly

<?php
if(isset($_POST['upload'])){
if($_FILES['file']['type']=="application/pdf")
{
if($_POST[upload] =="1")
{
$to="uploads/".$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'],$to);
echo "uploaded";
}

}
else
{
echo "it is not a pdf";
}
}
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="upload" value="1">
<input type="file" name="file">
<input type="submit" value="upload" name="upload">
</form>
ravi951
New php-forum User
New php-forum User
 
Posts: 26
Joined: Sat Jun 25, 2011 4:40 am

Re: uploading pdf's only

Postby rjtengco » Sat Jul 09, 2011 1:35 am

it's just the same from the source code I made. the only difference is you wrote an extra condition (if($_POST[upload] =="1")) but it sure will work.. nice keep it up.. cheers! :)
rjtengco
New php-forum User
New php-forum User
 
Posts: 25
Joined: Fri Jul 08, 2011 10:59 pm

Re: uploading pdf's only

Postby imarealy » Mon Jan 09, 2012 9:35 pm

How to make changes to a PDF file and save it without using expensive software? I have a few application forms downloaded in PDF format that require me filling and then send back. How do I open this PDF file and type things into it and then save, without using the expensive Adobe Acrobat suite?
_________________________
keyword research ~ keyword tool ~ keyword tracking ~ affiliate elite
Last edited by imarealy on Thu Jan 12, 2012 1:18 am, edited 1 time in total.
imarealy
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Jan 06, 2012 9:27 pm

Re: uploading pdf's only

Postby egami » Tue Jan 10, 2012 6:28 am

You simply cannot open a PDF file and change it. That's why it's a PDF.
You can open source, change source and create a PDF, but you cannot change a PDF.

Hope that helps.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: uploading pdf's only

Postby engrmudasirmalik » Wed Jan 11, 2012 12:16 pm

I think you should echo file type then replace your file type with that one.
I have observed that sometimes it changes the format from server to server. :-x
User avatar
engrmudasirmalik
New php-forum User
New php-forum User
 
Posts: 14
Joined: Wed Jan 11, 2012 11:39 am
Location: Bahawalpur Pakistan

Re: uploading pdf's only

Postby thandono » Thu Jan 12, 2012 9:57 am

Imagine if I create a text file and save it as "believe_me_this_is_a_pdf.pdf" :)
thandono
New php-forum User
New php-forum User
 
Posts: 44
Joined: Sun Jan 01, 2012 3:06 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.