PHP-PDO-to-Mysqli Conversion (FileUpload-FileDownload)
i have code upload file , download file in pdo. want convert mysqli. don't know how do.it's confusing me.
please me , convert pdo code mysqli code.
upload.php
<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<b></b><html>
<head>
<title>file upload utility</title>
</head>
<body>
<?php
if(isset($_post['cmdsubmit']) && $_files['userfile']['size'] > 0) {
extract( $_post );
$filename = $_files['userfile']['name'];
$tmpname = $_files['userfile']['tmp_name'];
$filesize = $_files['userfile']['size'];
$filetype = $_files['userfile']['type'];
// move_uploaded_file ($tmpname, "/temp/$filename");
// $tmpname = "/temp/$filename";
#$tmpname="c:/tmp/test.txt";
// echo "<h1>opening: $tmpname </h1>";
$fp = fopen($tmpname, 'r');
$content = fread($fp, filesize($tmpname));
# $content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc()) {
$filename = addslashes($filename);
}
$dsn = 'mysql:dbname=test;host=localhost;port=3306';
$user= 'root';
$password='';
try {
$dbh = new pdo($dsn, $user, $password);
$insertsql = $dbh->prepare(
"insert documents (email, full_name, file_name, " .
"file_size, file_bytes, file_type, received) values (?,?,?,?,?,?,sysdate())")
or die ($mysqli->error);
$insertsql->bindparam(1, $email, pdo::param_str, 60);
$insertsql->bindparam(2, $fullname, pdo::param_str, 60);
$insertsql->bindparam(3, $filename, pdo::param_str, 60);
$insertsql->bindparam(4, $filesize, pdo::param_int, 60);
$insertsql->bindparam(5, $content, pdo::param_str, $filesize);
$insertsql->bindparam(6, $filetype, pdo::param_str, 60);
// echo "<h1>about upload $filename database! $filesize</h1>";
$insertsql->execute() or die ("<p>upload error: $insertsql->error</p>");
} catch (pdoexception $e) {
die ('connection failed: '.$e->getmessage());
}
echo "<br>file $filename uploaded<br>";
}
?>
<a href="files.php">return file list</a>
</body>
</html>
download.php
<?php
//include("database.php");
$fileid = $_get["fileid"];
$sql = "select file_type, file_name, file_size, file_bytes documents file_id = ?";
$conn = mysqli_connect("localhost","root");
mysqli_select_db($conn,"test");
$dbh = new pdo($dsn,$user);
$stmt = $dbh->prepare($sql) or die(implode(':',$stmt->errorinfo()));
$stmt->bindparam(1,$fileid,pdo::param_int,60);
$stmt->execute() or die(implode(':',$stmt->errorinfo()));
$cols = $stmt->columncount();
$row = $stmt->fetch();
header("content-type: $row[0]");
header("content-length: $row[2]");
header("content-disposition: attachment; filename = $row[1]");
print $row[3];
?>
please me
More discussions in Dreamweaver support forum
adobe
Comments
Post a Comment