Member Avatar

I am worcking on a script that do that i can upload files to my site and set size,filename, etc into my database but this isnt worcking, can someone help me?:)

include "connect_profile.php";

$obj = new physic_profile();

// Setup our connection vars
$obj->host = '*********';
$obj->username = 'sjo*******';
$obj->password = '********';
$obj->db = 'sj******';

//Connect to our db

// Upload FIle
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'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);

    $fileName = addslashes($fileName);

$query = "INSERT INTO cms_profile (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

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

echo "<br>File $fileName uploaded<br>";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile"> 
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>

Member Avatar

Why are you using objects to connect to database ??? If you are sure that it's connecting to your database do this

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = mysql_real_escape_string($content);

$fileName = mysql_real_escape_string($fileName);
Be a part of the DaniWeb community

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