Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.