Sunday, May 18, 2008

Upload File - Auto Resize

langsung aja ya... ini scriptnya...:
btw berhubung aku upload error scriptnya, aku potong beberapa script.
jadi maklum kalau ada error hehehe

$error = false;
$file = false;
include "db.inc.php";
$upload_dir=dirname($_SERVER["SCRIPT_FILENAME"]);

if (!$error && isset($_REQUEST["uploadbutton"]))
$size = $_FILES["dumpfile"]["size"];
if ($size < 500000) {
{ if (is_uploaded_file($_FILES["dumpfile"]["tmp_name"]) && ($_FILES["dumpfile"]["error"])==0)
{
$uploaded_filename=str_replace(" ","_",$_FILES["dumpfile"]["name"]);
$uploaded_filepath=str_replace("//admin/files/","/",$upload_dir."/".$uploaded_filename);

if (file_exists($uploaded_filename))
{ echo ("

File $uploaded_filename already exist! Delete and upload again!

\n"); }
else if !@move_uploaded_file($_FILES["dumpfile"]["tmp_name"],$uploaded_filepath))
{ echo ("

Error moving uploaded file ".$_FILES["dumpfile"]["tmp_name"]." to the $uploaded_filepath

\n");
echo ("

Check the directory permissions for $upload_dir (must be 777)!

\n");
}
else
{ echo ("

Uploaded file saved as $uploaded_filename

\n");
$save = $uploaded_filename;
$file = $uploaded_filename;
header('Content-type: image/jpeg') ;
list($width, $height) = getimagesize($file) ;
$modwidth = 100;
$modheight = 100;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
// Here we are saving the .jpg, you can make this gif or png if you want
//the file name is set above, and the quality is set to 100%
imagejpeg($tn, $save, 100) ;
$filepath = "$uploaded_filename";
@unlink($filepath); }
}
else
{ echo ("

Error uploading file ".$_FILES["dumpfile"]["name"]."

\n");
}}}
else{echo "file kegedean $size";}
if ($filename==""){
?>
form method="POST" action=" echo '".$PHP_SELF."'; " enctype="multipart/form-data"
input type="hidden" name="MAX_FILE_SIZE" value="$upload_max_filesize"
p align="center">input type="file" name="dumpfile" accept="*/*" size="60"p align="center">input type="submit" name="uploadbutton" value="Upload"
/p>
/form>



Automatic Email Reporting with Attachment

Ada user yg butuh sistem untuk pengiriman email otomatis
dengan mengandalkan mr Google, dapet deh berbagai referensi untuk bikin email scheduler berikut:

ni untuk email.bat nya: tinggal ditulis di notepad, trs di save as *.bat
cd D:\php\ > folder dimana php berada
copy E:\ > file yg mo di attach
cd D:\php > lokasi php.exe
php D:\emailQC\mail.php > script buat ngirim

na ini isi file mail.php:

$to = "XXX";
$from = "XXX";
$cc = "XXX";
$bcc = "XXX";
$subject = "Load Assay Data";
$message = "\rDear all, \r\r Cuman ngetes pengiriman email dengan scheduler ni.... \r\rRegards,"; //

$fileatt="YYY";
$fileatt_type = $_FILES["YYY"]['type'];
$fileatt_name = "YYY";
$headers = "From: ".$from."\r\n";
$headers .= "Cc: ".$cc."\r\n";
$headers .= "Bcc: ".$bcc."\r\n";

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" ." boundary=\"{$mime_boundary}\"";
$message = "Email dengan attachment dan MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .$message . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: application/vnd.ms-excel\n" .
"Content-Disposition: attachment; filename=$fileatt_name\n".
"Content-Transfer-Encoding: base64\n\n" .$data . "\n\n" ."--{$mime_boundary}--\n";

$ok = @mail($to, $subject, $message, $headers);
?>

Scheduler Via PHP

Bulan lalu aku bikin sistem untuk kirim report otomatis pake scheduler di windows
tinggal tulis script berikut di notepad, terus di save as bat
tinggal di set aja scheduler biar bat tsb bisa dieksekusi di waktu yg kita inginkan
jadi dah...

cd c:\php > folder di mana php.exe berada
php D:\php\email.php > folder di mana file php yg mo dieksekusi berada

Create and Delete Windows Service

ternyata blogspot ndak di blok euy di sini ^_^
bisa ngupdate blog ni...

kemarin aku ada masalah dengan setingan php-mysql.
SQL service udah dibuat, ternyata nggak jalan. nah pas buat service baru, service lama nggak bisa di delete. browsing punya browsing, akhirnya dapet ni jurus jitu buat remove service:
sc delete

terus kalau mau create service baru:
sc create

dapet infonya dari sini ni...

sebelum di delete, service musti di disable dulu, kalo nggak, dia ga mo ilang dan musti di restart dulu