Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,486 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,686 people online right now. Registration is fast and FREE... Join Now!




upload a pdf to root directory using php form

 
Reply to this topicStart new topic

upload a pdf to root directory using php form

sgraphics
24 Feb, 2008 - 01:24 AM
Post #1

New D.I.C Head
*

Joined: 23 Feb, 2008
Posts: 1

I can use this to upload html and txt files but it won't work for pdf files can someone please help me figure this out.

Here is the form I'm using:
CODE

<?php

echo "<title>file upload</title>";
echo "<h1 align=\"left\">File Upload</h1>";
echo "<div align=\"left\">";
echo "<style type=\"text/css\">
BODY{font-family:Verdana, Arial, Helvetica, sans-serif}
</style><form method=post action=\"upload2a.php\" enctype=\"multipart/form-data\">
<p>Update for: Dinner Menu<br>Select a file to Upload: <br><input type=file name=img1 size=30></p>
<p><input type=submit value=\"Upload File\"></p></form>"
?>


Here is the upload php file:

<?php
$webServer="/home/mcguire/public_html/";

echo "<title>file upload</title>";
echo "<h1 align=\"left\">File Upload</h1>";
echo "<div align=\"left\">";
echo "<style type=\"text/css\">
BODY{font-family:Verdana, Arial, Helvetica, sans-serif}
</style>";

# Check whether file is uploaded successfully
if($img1_name == "McGuires-Dinner.pdf"){
    @copy("$img1","$webServer$img1_name") or die("FAILURE! Please double check your file.<br><br><a href=\"uploadform2a.php\">&laquo;Go back</a>");
}
else{
    die("FAILURE! $img1_name is not the correct file.<br><br><a href=\"uploadform2.php\">&laquo;Go back</a>");

}
echo "<html><head><title>Successful File Upload!</title></head><body><h2>Success!</h2>
<p>Your website has been updated.<br><br>The following file has been uploaded: $img1_name<br>Size: $img1_size byte<br>Type: $img1_type.</p>
<a href=\"uploadform2a.php\">&laquo;Go back to upload form</a></body></html>";
?>

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Upload A Pdf To Root Directory Using Php Form
24 Feb, 2008 - 01:39 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,947



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Moved to PHP.

Use code.gif tags when posting code and post your questions in the correct forum.
User is online!Profile CardPM
+Quote Post

SpaceMan
RE: Upload A Pdf To Root Directory Using Php Form
24 Feb, 2008 - 06:50 PM
Post #3

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

not recomended to upload to server http root, security issue.
maybe what is causing the error, but you are able to do others.

make a new dir. cmod to 0777
/home/mcguire/uploads

unless php has changed , dont actually see how this will work.
it uploads to php tmp dir and then copy it from their.

try to modify one i have, you may need to adjust it.
CODE

move_uploaded_file($_FILES['img1']['tmp_name'], $webServer.'/'.$_FILES['img1']);





User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:24PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month