dear all,

I want to make a digital library goverment regulation which related to export import activity in my aoffice. The problem is:
I dont know how to upload the .pdf file to local server and provide the link to acess it automatically, Please help me..:(

Upload the PDF files to a directory and have the PHP script check the directory and list any PDF files in there.

When uploading the file I think you mean to the remote server, and you can just use an FTP client for this such as Filezilla, Dreamweaver, FTP Pro, LeechFTP, etc...

When linking to the pdf document make sure you use
$_SERVER

And then the file path and filename to the PDF file.

When uploading the file I think you mean to the remote server, and you can just use an FTP client for this such as Filezilla, Dreamweaver, FTP Pro, LeechFTP, etc...

When linking to the pdf document make sure you use
$_SERVER

And then the file path and filename to the PDF file.

Hi,
Instead of simply specifying the link as

<a href="www.sitename.com/documentname.pdf">DocumentPDF</a> , why should we use $SERVER['DOCUMENT_ROOT']

???
Is there any specific advantage with that?! Please let me know as am a novice.
Thank you.

Sorry, I meant if you're using a force download or if you're attaching the PDF in an email.

If you're simply linking to it then you can just use the relative file path.

Sorry for the confusion.

Sorry, I meant if you're using a force download or if you're attaching the PDF in an email.

If you're simply linking to it then you can just use the relative file path.

Sorry for the confusion.

Ok, so $SERVER forces download.
Thank you dats a good info.

Adding that code doesn't force the download, but when using force download with PDFs you can't use a relative file path, you must go back to the root.

To do a force download you will first need to set some PHP headers at the top of your page.

So why not just use an anchor link for downloading? using PHP seems a bit tricky and long winded to me. The user will have to click a link a some point to get to the page so if you want it to automatically download just write the ducoment into the anchor text like <a href"http://www.somesite.com/thepdf.pdf">the pdf</a> - it will be a lot easier in the long run :)

Thank you a lot for your advice. I have try the code
and I found the suitable one

function upload_dir()
{
    $dir = $_SERVER['PHP_SELF'];
    for($i=0;$i<strlen($dir);$i++){
        if(substr($dir,$i,1)=="/") $slashpos=$i;
    }
    $dir = substr($dir,0,$slashpos);
    $dir = $_SERVER['DOCUMENT_ROOT'].$dir."/files/";
    return($dir);
}

if($upl==1){
    $uploaddir = upload_dir();
    $uploaddir=$uploaddir.substr($ext,0);

    if(!file_exists($uploaddir))
    {
        makeindex($uploaddir."log.txt");
    }

    $uploadfile = $uploaddir.$_FILES['userfile']['name']; 

    if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
    {
       $address = getimgplace(substr($ext,0));
       echo "File is valid, and was successfully uploaded.<br>\n";
       echo "Location:<font color=\"blue\"><b> $address </b></font>\n";
       echo "Copy the blue address as the link address! <br> <br> \n";
       echo "Your IP: <font color=\"red\">".$_SERVER['REMOTE_ADDR']."</font>\n";

       //menyimpan alamat upload
       include "cd_connect.inc.php";
       pg_dbname();
       $query = "INSERT INTO t_master_reg VALUES ('$kode',null,null,null,null,null,null,'$address',null)";
       pg_query($connection,$query);
       header("location:frm_input_reg.php");     

    }
    else
    {
       echo "Possible file upload attack!\n";
    }
}

thank you very much :)

see this

PHP » File Directory » File Upload         
    
Upload PDF file and rename it

<form action="<?php print $PHP_SELF?>" enctype="multipart/form-data" method="post">
   Last Name:<br /> <input type="text" name="name" value="" /><br />
   Class Notes:<br /> <input type="file" name="classnotes" value="" /><br />
   <p><input type="submit" name="submit" value="Submit Notes" /></p>
</form>

<?php
   define ("FILEREPOSITORY","./");

   if (is_uploaded_file($_FILES['classnotes']['tmp_name'])) {

      if ($_FILES['classnotes']['type'] != "application/pdf") {
         echo "<p>Class notes must be uploaded in PDF format.</p>";
      } else {
         $name = $_POST['name'];
         $result = move_uploaded_file($_FILES['classnotes']['tmp_name'], FILEREPOSITORY."/$name.pdf");
         if ($result == 1) echo "<p>File successfully uploaded.</p>";
         else echo "<p>There was a problem uploading the file.</p>";
      } #endIF
   } #endIF
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.