Tuesday, June 23, 2015

PHP Upload or Store Images in the Database SQL SERVER

 <form action="../library/edit.php" method="post"  enctype="multipart/form-data" id="frm_logo" name="frm_logo" style="display:none">
        <input type="file" name="imagefile" id="imagefile">
        <input type="hidden" name="Company_ID" id="Company_ID">
        <input type="submit" value="Upload">
        </form>


$filedata = fread(fopen($_FILES['imagefile']['tmp_name'], 'r'),
               $_FILES['imagefile']['size']);
$fileName = $_FILES['imagefile']['name'];
$tmpName  = $_FILES['imagefile']['tmp_name'];
$fileSize = $_FILES['imagefile']['size'];
$fileType = $_FILES['imagefile']['type'];

$sql="INSERT INTO dbo.DBGAMBAR(Company_ID, Logo, LogoFileName, ExtFileName)
 VALUES (?,?,?,?) ;";
 $params=array($_POST['Company_ID'],array(
                        &$filedata,
                        SQLSRV_PARAM_IN,
                        SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY),
                        SQLSRV_SQLTYPE_VARBINARY('max')
                        ) , $fileName, $fileType);
 sqlsrv_query($conn, $sql, $params, array("Scrollable"=>"buffered"))
or die ("Gagal Perintah SQL". sqlsrv_errors());

No comments:

Post a Comment