upload pdf

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

37 Replies - 32487 Views - Last Post: 13 October 2008 - 08:15 PM Rate Topic: -----

#1 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

upload pdf

Posted 04 October 2005 - 08:01 AM

hey, so i have a client that has important alerts put into pdf file. what i need is to upload it to the server, but save the dir i guess in the database this way it links to it. i dont know how to go about doing this. i created a basic user management system so they can update everything on their own. i figured i would need a basic upload field and what not to get it on the server. but how would i store it in database so that it automaticly say links up with id=1 so i can do something like pdf.php?id=1 and it downloads the pdf file for that feild in the data base.

Is This A Good Question/Topic? 0
  • +

Replies To: upload pdf

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: upload pdf

Posted 04 October 2005 - 08:09 AM

You could implement a numerical primary key (even an auto number) that you coud then link to...if you need to store it in the record in a position other than the primary key filed, you can pull the last record, check the ID, increment by one, then insert the new ID...see what I mean, or am I misunderstanding the problem.
Was This Post Helpful? 0
  • +
  • -

#3 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: upload pdf

Posted 04 October 2005 - 09:06 AM

uuuhhhhh..... ok.... ummm i didnt understand much of that.

Problem:
Client wants alerts to be is pdf format on the website.
I need it so i can link the pdf through the database. im just not sure how i do this, so i know have an upload field that would put them all on the server. but then i need the database to be able to call it. if it is something like pdf.php?id=2 or links right to the pdf i dont care. as long as the database stores a way for me to link to the right pdf file. ive never done something like this.

i have these feilds in the database name
alertID - INT, auto_increment, primary
alertCat - text
alertDate - text (i didnt use a time stamp cause sometimes there is not specific dates)
alert - Long Text ( originally it was suppose to be all text. now this feild will be a brief summary of the alert)
Was This Post Helpful? 0
  • +
  • -

#4 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: upload pdf

Posted 04 October 2005 - 01:22 PM

ok so i found this tutorial on hoe to do this. like adding it to the database a blob, now i just dont know how to add it to my current form i have. http://www.php-mysql...ysql-upload.php

this is the sql they told me to have
CREATE TABLE upload (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
size INT NOT NULL,
content MEDIUMBLOB NOT NULL,
PRIMARY KEY(id)
);


so i figured i would add the name,type,size, and content to my current one. just change it a bit like pdfName, ect. since i already have the id as primary id and what not.

this is the upload page they said i should use.
<html>
<head>
<title>Upload File To MySQL Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.box {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    border: 1px solid #000000;
}
-->
</style>
</head>

<body>
<?
if(isset($_POST['upload']))
{
        $fileName = $_FILES['userfile']['name'];
        $tmpName  = $_FILES['userfile']['tmp_name'];
        $fileSize = $_FILES['userfile']['size'];
        $fileType = $_FILES['userfile']['type'];
        
        $fp = fopen($tmpName, 'r');
        $content = fread($fp, $fileSize);
        $content = addslashes($content);
        fclose($fp);
        
        if(!get_magic_quotes_gpc())
        {
            $fileName = addslashes($fileName);
        }
        

        include 'library/config.php';
        include 'library/opendb.php';
        
        $query = "INSERT INTO upload (name, size, type, content ) ".
                 "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

        mysql_query($query) or die('Error, query failed');                    
        include 'library/closedb.php';
        
        echo "<br>File $fileName uploaded<br>";
}        
?>
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
  <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
    <tr> 
      <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile">
         </td>
      <td width="80"><input name="upload" type="submit" class="box" id="upload" value="  Upload  "></td>
    </tr>
  </table>
</form>
</body>
</html>



now i dont know how this is going to work. like how does it know the size or what not. do i need all that? or can i just create a feild and have it go in as blob and everything else should be good?

im confused...
Was This Post Helpful? 0
  • +
  • -

#5 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: upload pdf

Posted 04 October 2005 - 06:02 PM

Was the plan to store the pdf documents on the server? If so, then you really only need to store an ID and the path to the document itself...then when you create the page (say a page of alerts), your link would be made with the path to the document from the database.

Or were you planning on storing the document itself in the database?

As for the size, you won't know that unless you request it when uploading, or another time, using one of the files system functions that php provides...you really only need that, however, if you're planning to stop files above or below a certain size from being uploaded.
Was This Post Helpful? 0
  • +
  • -

#6 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: upload pdf

Posted 05 October 2005 - 09:53 PM

yeah storing the dir in the database would be fine. how would i do this?
Was This Post Helpful? 0
  • +
  • -

#7 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: upload pdf

Posted 06 October 2005 - 12:05 PM

ok so is there a way i can store the dir in the database. but it needs to beable to store the name or something right? like say upload it www.website.com/pdfs/ but it knows its call say file100505.pdf. this way i can call it? and how would i call it? just link it to the varible of the database its stored in? i have never done this before... so im not to sure how to do this.
Was This Post Helpful? 0
  • +
  • -

#8 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: upload pdf

Posted 07 October 2005 - 12:53 PM

*bump*
Was This Post Helpful? 0
  • +
  • -

#9 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: upload pdf

Posted 07 October 2005 - 01:05 PM

Sorry iamcenz...kinda lost track of this one. Before we get too deep about storing the directory, would you like to use the script you have? That script is meant to store actual content of the pdf files in the database, which we can certainly do...but in that case, there is no need to store the directory. Essentially it comes to this:

Do you want to store the document itslef in the database, or store the document on the hard drive of your server?
Was This Post Helpful? 0
  • +
  • -

#10 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: upload pdf

Posted 07 October 2005 - 11:04 PM

which seems more logical to do? there is prolly going to be upwards of 6-7 pdfs a week at about 2-3mb each. space really isnt going to be much of an issue. just im worried about speed. i dont want it to take forever to load the pdf. also which is easier to do. remember im still a n00b when it comes to this stuff. so yeah either one will work. just i got a form set up, which adds content to the data base, like a small blurb and the date and which cat it belongs in, i need it to work that forms script. i will post the script in the morning.
Was This Post Helpful? 0
  • +
  • -

#11 cyberscribe  Icon User is offline

  • humble.genius
  • member icon

Reputation: 10
  • View blog
  • Posts: 1,062
  • Joined: 05-May 02

Re: upload pdf

Posted 07 October 2005 - 11:49 PM

Store the PDFs in one or more directories. Store the file name (and directory path if there are multiple directories) in the database. It will be faster and less hassle. Just because you can store binary data in a database doesn't mean you necessarily should, and in this case, you're going to have an easier time of it dealing with the file system.

Do you know how to upload files in PHP? Do you know how to pass a binary file directly through PHP? Do you know how to set the correct Content-Type and Content-Disposition headers in PHP to tell the browser it's a PDF?

If so, you're set. :)
Was This Post Helpful? 0
  • +
  • -

#12 cybrid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 07-September 05

Re: upload pdf

Post icon  Posted 08 October 2005 - 03:32 PM

I agree with cyberscribe, storing binary files in the database can slow a bit too much, it's totaly better to store the path to the file in a field, and then provide a ftp or url link to the file. Specialy if those pdf files are big. ;)

Just store the path, then retrieve it through a query, and put a link to it in your page. Also I think it's not difficult to achieve that; I'm sure you'll manage to make it :)

This post has been edited by cybrid: 08 October 2005 - 03:33 PM

Was This Post Helpful? 0
  • +
  • -

#13 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: upload pdf

Posted 11 October 2005 - 11:24 AM

wow sorry it took so long for me to reply on here. ok, i can figure out the uploading it to the server, but how do i store the path and file name in the database? also, can i include the file upload form in witht he one i currently have? if so how do i do that?
Was This Post Helpful? 0
  • +
  • -

#14 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: upload pdf

Posted 11 October 2005 - 11:28 AM

here is the current page that puts the data i the data base. how can i make this still put what it needs in the database plus upload the pdf to the server and store the path to the database

<?php require_once('../Connections/conn.php'); ?>
<?php
session_start();
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO Alerts (alertID, alertCat, alertDate, alert, alertPdf) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['alertID'], "int"),
                       GetSQLValueString($_POST['alertCat'], "text"),
                       GetSQLValueString($_POST['alertDate'], "text"),
                       GetSQLValueString($_POST['alert'], "text"),
                       GetSQLValueString($_POST['pdf'], "text"));

  mysql_select_db($database_conn, $conn);
  $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());

  $insertGoTo = "alerts.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_conn, $conn);
$query_tradeAlerts = "SELECT * FROM Alerts WHERE alertCat = 'TradeAlerts'";
$tradeAlerts = mysql_query($query_tradeAlerts, $conn) or die(mysql_error());
$row_tradeAlerts = mysql_fetch_assoc($tradeAlerts);
$totalRows_tradeAlerts = mysql_num_rows($tradeAlerts);

$colname_chempharmAlerts = "1";
if (isset($_GET['ChemPharm'])) {
  $colname_chempharmAlerts = (get_magic_quotes_gpc()) ? $_GET['ChemPharm'] : addslashes($_GET['ChemPharm']);
}
mysql_select_db($database_conn, $conn);
$query_chempharmAlerts = sprintf("SELECT * FROM Alerts WHERE alertCat = '%s'", $colname_chempharmAlerts);
$chempharmAlerts = mysql_query($query_chempharmAlerts, $conn) or die(mysql_error());
$row_chempharmAlerts = mysql_fetch_assoc($chempharmAlerts);
$totalRows_chempharmAlerts = mysql_num_rows($chempharmAlerts);

$colname_biweeklyAlerts = "1";
if (isset($_GET['BiWeekly'])) {
  $colname_biweeklyAlerts = (get_magic_quotes_gpc()) ? $_GET['BiWeekly'] : addslashes($_GET['BiWeekly']);
}
mysql_select_db($database_conn, $conn);
$query_biweeklyAlerts = sprintf("SELECT * FROM Alerts WHERE alertCat = '%s'", $colname_biweeklyAlerts);
$biweeklyAlerts = mysql_query($query_biweeklyAlerts, $conn) or die(mysql_error());
$row_biweeklyAlerts = mysql_fetch_assoc($biweeklyAlerts);
$totalRows_biweeklyAlerts = mysql_num_rows($biweeklyAlerts);

$colname_fdaAlerts = "1";
if (isset($_GET['FDA'])) {
  $colname_fdaAlerts = (get_magic_quotes_gpc()) ? $_GET['FDA'] : addslashes($_GET['FDA']);
}
mysql_select_db($database_conn, $conn);
$query_fdaAlerts = sprintf("SELECT * FROM Alerts WHERE alertCat = '%s'", $colname_fdaAlerts);
$fdaAlerts = mysql_query($query_fdaAlerts, $conn) or die(mysql_error());
$row_fdaAlerts = mysql_fetch_assoc($fdaAlerts);
$totalRows_fdaAlerts = mysql_num_rows($fdaAlerts);

mysql_select_db($database_conn, $conn);
$query_a = "SELECT * FROM Alerts";
$a = mysql_query($query_a, $conn) or die(mysql_error());
$row_a = mysql_fetch_assoc($a);
$totalRows_a = mysql_num_rows($a);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Admin CP Alerts : New</title>
<link href="../styles.css" rel="stylesheet" type="text/css">
<script language="Javascript" type="text/Javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<style type="text/css">
<!--
body {
	background-color: #000000;
}
-->
</style></head>

<body onload="MM_preloadImages('../images/serko4_04_over.jpg','../images/serko4_06_over.jpg','../images/serko4_08_over.jpg','../images/serko4_12_over.jpg','../images/serko4_14_over.jpg','../images/serko4_16_over.jpg','../images/serko4_17_over.jpg')">
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2" style="background-image:url(../images/bgtop.jpg)"><img src="../images/serko3_01.jpg" width="656" height="191"></td>
  </tr>
  <tr style="background-image:url(../images/navbg.jpg) ">
    <td width="90%"><img src="../images/serko4_02_over.jpg" width="40" height="41"><img src="../images/serko4_03.jpg" width="5" height="41"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','../images/serko4_04_over.jpg',1)"><img src="../images/serko4_04.jpg" name="Image4" width="62" height="41" border="0"></a><img src="../images/serko4_05.jpg" width="5" height="41"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image6','','../images/serko4_06_over.jpg',1)"><img src="../images/serko4_06.jpg" name="Image6" width="59" height="41" border="0"></a><img src="../images/serko4_07.jpg" width="5" height="41"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image8','','../images/serko4_08_over.jpg',1)"><img src="../images/serko4_08.jpg" name="Image8" width="62" height="41" border="0"></a><img src="../images/serko4_09.jpg" width="5" height="41"><img src="../images/serko4_10.jpg" width="100" height="41"><img src="../images/serko4_11.jpg" width="5" height="41"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image12','','../images/serko4_12_over.jpg',1)"><img src="../images/serko4_12.jpg" name="Image12" width="57" height="41" border="0"></a><img src="../images/serko4_13.jpg" width="5" height="41"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image14','','../images/serko4_14_over.jpg',1)"><img src="../images/serko4_14.jpg" name="Image14" width="64" height="41" border="0"></a><img src="../images/serko4_15.jpg" width="3" height="41"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image16','','../images/serko4_16_over.jpg',1)"><img src="../images/serko4_16.jpg" name="Image16" width="89" height="41" border="0"></a></td>
    <td width="10%"><div align="center"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image17','','../images/serko4_17_over.jpg',1)"><img src="../images/serko4_17.jpg" name="Image17" width="116" height="41" border="0"></a></div></td>
  </tr>
  <tr style="background-color:#000000">
    <td colspan="2"><table width="95%"  border="0" align="center" cellpadding="2" cellspacing="0">
      <tr>
        <td width="19%" valign="top"><? include('cpnav.php'); ?></td>
        <td width="81%" valign="top" class="maintxt"><form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
          <p>
            <input name="alertID" type="hidden" id="alertID">
            <br>
            Alert Category:<br>
            <select name="alertCat" class="form" id="alertCat">
                <option value="TradeAlerts" <?php if (!(strcmp("TradeAlerts", $row_a['alertCat']))) {echo "SELECTED";} ?>>Trade Alerts</option>
                <option value="BiWeekly" <?php if (!(strcmp("BiWeekly", $row_a['alertCat']))) {echo "SELECTED";} ?>>Bi-Weekly</option>
                <option value="ChemPharm" <?php if (!(strcmp("ChemPharm", $row_a['alertCat']))) {echo "SELECTED";} ?>>Chem &amp; Pharm</option>
                <option value="FDA" <?php if (!(strcmp("FDA", $row_a['alertCat']))) {echo "SELECTED";} ?>>FDA</option>
            </select> 
            <br>
            Alert:<br>
            <textarea name="alert" cols="85" rows="30" class="form" id="alert"></textarea>
            <br>
            Date: 
            <input name="alertDate" type="text" class="form" id="alertDate">
  (ex. mm/dd/yyyy)  <br>
              <input name="Submit" type="submit" class="form" value="Submit">
              <input type="hidden" name="MM_insert" value="form1">        
              </p>
          </form>
  </td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($tradeAlerts);

mysql_free_result($chempharmAlerts);

mysql_free_result($biweeklyAlerts);

mysql_free_result($fdaAlerts);

mysql_free_result($a);
?>


Was This Post Helpful? 0
  • +
  • -

#15 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: upload pdf

Posted 12 October 2005 - 12:56 PM

ttt :crazy:
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3