I am evaluating vault to use in my application.
Implementing vault 1.6 into my application was no problem.
However, I want to save the filename and some other values, real name of the file, hash-code, timestamp etc. to a mysql-database using php.
Does anyone have a tutorial or an idea how to do this?
xlthor
October 17, 2010, 6:23am
#2
Check the samples from the zip, ‘UploadHandler.php’
To store to a database, code should be something like this:
$inputName = $_GET['userfile'];
$fileName = $_FILES[$inputName]['name'];
$tempLoc = $_FILES[$inputName]['tmp_name'];
$target_path = './uploads/';
$target_path = $target_path . basename($fileName);
if(move_uploaded_file($tempLoc,$target_path))
{
$_SESSION['dhxvlt_state'] = -1;
} else {
$_SESSION['dhxvlt_state'] = -3;
}
if ( isset($_FILES[$inputName]) && $_FILES[$inputName]['error'] == 0 ) {
// Jetzt haben wir eine Datei, die wir mal einlesen:
$blob = file_get_contents($target_path);
$pi = pathinfo($fileName);
$fExt = $pi['extension'];
$fName = basename($fileName, ".".$fExt);
$crId = $_REQUEST['crId'];
$fType = $_FILES[$inputName]['type'];
....
// alles fertig zum ablegen
storeCreativeBlob($crId, $fName, $fExt, $fType, $blob, $w, $h, $color);
// aufräumen
@unlink($target_path);
}
....
function storeCreativeBlob($cr, $fName, $fExt, $fType, $blob, $w, $h, $color)
{
$conn = $this->getConn();
$sql = "UPDATE CREATIVES SET " .
"cr_media = '" . $fType . "', " .
"cr_data = '" . mysql_real_escape_string($blob, $conn) . "', " .
"cr_filename = '" . $fName . "', " .
($w != null && $h != null && $color != null ? (
"cr_sizeX = " . $w . ", " .
"cr_sizeY = " . $h . ", " .
"cr_colorscheme = '" . $color . "', " ) : ""
) .
"cr_suffix = '" . $fExt . "' " .
"WHERE cr_id = '" . $cr . "'";
...
Is it possible to include(pagename.php) within the UploadHandler.php to do some processing of the uploaded file?
Fedor
March 31, 2011, 2:45pm
#4
Yes, please see the above sample.