Jump to content

MYSQL upload issues


Ltj_bukem

Recommended Posts

I'm trying to create a script to upload files to the database, from what I have read I have to first upload the file to the sever and then read the contents into MYSQL. Here's the script but nothing appears in the database or the server.

 

<html>

<head>

<title>Upload</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);

}

 

 

 

$dbhost = '****';

$dbuser = '*****';

$dbpass = '******';

$dbname = '*****';

 

          $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

mysql_select_db($dbname)

 

 

$query = "INSERT INTO download (name, size, type, content ) ".

        "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

 

mysql_query($query) or die('Error, query failed');

//include 'library/closedb.php';

 

 

}

 

?>

<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>

Link to comment
https://forums.phpfreaks.com/topic/71800-mysql-upload-issues/
Share on other sites

I'm getting a 'Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\htdocs\uploadform.php on line 33'

 

this is the following line(s)

 

$query = "INSERT INTO download (name, size, type, content ) ".

        "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

 

I'm guessing something is not right with the database.

 

 

Link to comment
https://forums.phpfreaks.com/topic/71800-mysql-upload-issues/#findComment-361711
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.