The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> PHP, how to upload pdf into phpmyadmin
thedropout
post Jan 22 2015, 12:24 PM
Post #1





Group: Members
Posts: 5
Joined: 22-January 15
Member No.: 22,065



Hi i am trying to upload pdf files into phpmyadmin with this form but i get this error. Is there anyway to do it? Also, i have the rest of the code for the php script
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1"
cellspacing="1" class="box">
<tr>
<td>please select a file</td></tr>
<tr>
<td>
<input type="hidden" name="MAX_FILE_SIZE"
value="16000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload"
type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>
<?php

<?php
if(isset($_POST['upload'])&&$_FILES['userfile']['size']>0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fileType=(get_magic_quotes_gpc()==0 ? mysql_real_escape_string(
$_FILES['userfile']['type']) : mysql_real_escape_string(
stripslashes ($_FILES['userfile'])));
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$con = mysql_connect('localhost', 'root', 'root') or die(mysql_error());
$db = mysql_select_db('olearyinternational', $con);
if($db){
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
mysql_close();
echo "<br>File $fileName uploaded<br>";
}else { echo "file upload failed"; }
}
?>

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<form method="post" enctype="multipart/form-data">
<table width="350" border="0' at line 1
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Kelly008
post Apr 1 2015, 04:39 AM
Post #2


Newbie
*

Group: Members
Posts: 15
Joined: 1-April 15
Member No.: 22,440



You should check for the quotes. May be conflicting.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post Apr 1 2015, 08:00 AM
Post #3


Programming Fanatic
********

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9



The OP probably should search for "upload pdf files into phpmyadmin", although you don't upload files to PHPMyAdmin but add them into a DB, which then can be verified in PMA.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Apr 14 2015, 08:03 AM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



That form doesn't upload anything anywhere that I can see. It lacks the action attribute.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Themeaxe
post Jul 18 2016, 07:07 AM
Post #5


Newbie
*

Group: Members
Posts: 10
Joined: 18-July 16
Member No.: 24,423



Hello, by using this code I have uploaded pdf file in phpmyadmin. Firstly save as upload.php .You can try this code:

<?php
if(isset($_POST['btn-upload']))
{

$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";

move_uploaded_file($file_loc,$folder.$file);
$sql="INSERT INTO tbl_uploads(file,type,size) VALUES('$file','$file_type','$file_size')";
mysql_query($sql);
}
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th March 2024 - 12:48 AM