Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Tuesday, November 10, 2015

fix send-mail: Authorization failed 534

It may take more than one step to fix this issue
  1. Take the step mentioned earlier. Log into your google email account and then go to this link:https://www.google.com/settings/security/lesssecureapps and set "Access for less secure apps" to ON. Test to see if your issue is resolved. If it isn't resolved, as it wasn't for me, continue to Step #2.
  2. Go to https://support.google.com/accounts/answer/6009563 (Titled: "Password incorrect error"). This page says "There are several reasons why you might see a “Password incorrect” error (aka 534-5.7.14) when signing in to Google using third-party apps. In some cases even if you type your password correctly." This page gives 4 suggestions of things to try.

Friday, October 23, 2015

Add/Customize Meta fields to Edit Media Attachment Wordpress

/* For adding custom field to gallery popup */
function add_image_attachment_fields_to_edit($form_fields, $post) {
  // $form_fields is a an array of fields to include in the attachment form
  // $post is nothing but attachment record in the database
  //     $post->post_type == 'attachment'
  // attachments are considered as posts in WordPress. So value of post_type in wp_posts table will be attachment
  // now add our custom field to the $form_fields array
  // input type="text" name/id="attachments[$attachment->ID][custom1]"
  $form_fields["credit"] = array(
    "label" => __("Credit"),
    "input" => "text", // this is default if "input" is omitted
    "value" => get_post_meta($post->ID, "_credit", true),
                "helps" => __("Help string."),
  );
   return $form_fields;
}
// now attach our function to the hook
add_filter("attachment_fields_to_edit", "add_image_attachment_fields_to_edit", null, 2);

function add_image_attachment_fields_to_save($post, $attachment) {
  // $attachment part of the form $_POST ($_POST[attachments][postID])
        // $post['post_type'] == 'attachment'
  if( isset($attachment['credit']) ){
    // update_post_meta(postID, meta_key, meta_value);
    update_post_meta($post['ID'], '_credit', $attachment['credit']);
  }
  return $post;
}
// now attach our function to the hook.
add_filter("attachment_fields_to_save", "add_image_attachment_fields_to_save", null , 2);

Sunday, October 11, 2015

Add Specific Minutes in DateTime PHP

date_default_timezone_set("asia/jakarta");
$minutes_to_add =1;
$time = new DateTime(date("Y-m-d H:i:s"));
$time->add(new DateInterval('PT' . $minutes_to_add . 'M'));
$stamp = $time->format('Y-m-d H:i:s');

Monday, September 21, 2015

Displaying SQL Server Column Names in PHP

<?php

$stmt = sqlsrv_query( $conn, $query[0] );
foreach( sqlsrv_field_metadata( $stmt ) as $fieldMetadata  ) {
echo '<td>' .$fieldMetadata['Name'].'</td>';
//foreach( $fieldMetadata as $name => $value) {
 // echo "$name: $value<br />";
//}
// echo "<br />";
}
?>

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());

Saturday, February 8, 2014

show next record of data from database (MySql)

<?php
$category_id=$rsctgrarticle['category_id'];
$sqlsubctgrarticle = "select * from subcategory where category_id='$category_id'";
$qrysubctgrarticle = mysql_query($sqlsubctgrarticle, $koneksi);
$hslsubindoPeriksa = mysql_num_rows($qrysubctgrarticle);
$no=1;
if (trim($hslsubindoPeriksa)!=0){
?>
<?php
$a=1;
for ($a=1;$a<=$hslsubindoPeriksa;$a=$a+2){
mysql_data_seek($qrysubctgrarticle, $a);
echo "<table border=1>";
$row = mysql_fetch_row($qrysubctgrarticle);
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>";
mysql_data_seek($qrysubctgrarticle, $a+1);
$rowb = mysql_fetch_row($qrysubctgrarticle);
echo "<td>&nbsp;</td><td>$rowb[0]</td><td>$rowb[1]</td><td>$rowb[2]</td> </tr>";
}
echo "</table>";
?>

Monday, January 27, 2014

to set file size limit in upload large file

1. set in (.htaccess)
php_value upload_max_filesize 3G
php_value post_max_size 3G

2. set in upload.php action
<?php
ini_set('upload_max_filesize', '3G');
ini_set('post_max_size', '3G');

$uploaddir = 'upload/';

$file = basename($_FILES['userfile']['name']);
$uploadfile = $uploaddir . $file;

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "OK";
}
else {
echo "ERROR";
}
?>

3. form
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" id="userfile" size="20" name="userfile">
<input type="submit" value="Upload" name="submit">
</form>

Modif html file content

$title=stripslashes($_POST['title']);
$unit=stripslashes($_POST['unit']);
$isi=stripslashes($_POST['setatus']);
copy("berita_new.html", "../berita/berita_new.html");
rename ("../berita/berita_new.html", "../berita/".$title.".html");
// create file pointer 
$fp = @fopen('../berita/'.$title.'.html', 'w') or die('Could not open file, or fike does not exist and failed to create.');

$mytext = $isi;

// write text to file
@fwrite($fp, $mytext) or die('Could not write to file.');
// close file
@fclose($fp);

echo "<meta http-equiv='refresh' content='0; url=../berita/".$title.".html'>";

Tuesday, December 3, 2013

get curent URL in PHP

<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

$url=curPageURL();
?>