ไฟล์ index.php......
<?php
header ('Content-Type: text/html; charset=utf-8');
$maxsize = 300 * 1024;
$baseurl = 'http://www................./forum/imageupload/data/';
$basedir = './data/';
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--
-
- the DtTvB's Mini Image Uploader
- by the DtTvB [http://dt.in.th/]
-
- Inspired by f0nt forum's one.
- [http://www.f0nt.com/forum/]
-
-->
<title>Upload</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="mini-upload.css" />
</head>
<body>
<?php
if (isset($_FILES['userfile'])) {
function show_error($msg) {
echo '<center><font color=red><strong>Error: </strong>' . $msg . ' — <a href="./index_th.php">Back</a></font></center>';
return true;
}
$extensions = array(
IMAGETYPE_GIF => '.gif',
IMAGETYPE_JPEG => '.jpg',
IMAGETYPE_PNG => '.png',
IMAGETYPE_SWF => '.swf',
IMAGETYPE_SWC => '.swf'
);
$creators = array(
IMAGETYPE_GIF => 'imagecreatefromgif',
IMAGETYPE_JPEG => 'imagecreatefromjpeg',
IMAGETYPE_PNG => 'imagecreatefrompng'
);
function get_random_text() {
return base_convert(time(), 10, 36) . '-' . substr(md5(microtime()), 8, 6);
}
function get_upload_fname($p, $a) {
global $basedir;
do {
$name = $p . get_random_text() . $a;
} while (file_exists($basedir . $name));
return $name;
}
do {
if ($_FILES['userfile']['size'] < 1 || $_FILES['userfile']['size'] > $maxsize) {
show_error ('Image file is too large.');
break;
}
if ($_FILES['userfile']['error']) {
show_error ('An error has occured while uploading.');
break;
}
$imagesize = @getimagesize($tmp_name = $_FILES['userfile']['tmp_name']);
if (empty($imagesize)) {
show_error ('Image type is unsupported by PHP.');
break;
}
if (!in_array($imagesize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_SWF, IMAGETYPE_SWC))) {
show_error ('Image type is unsupported by Uploader.');
break;
}
$xt = $extensions[$imagesize[2]];
$cr = $creators[$imagesize[2]];
$ow = $imagesize[0];
$oh = $imagesize[1];
if ($imagesize[2] == IMAGETYPE_SWF || $imagesize[2] == IMAGETYPE_SWC) {
$fname = get_upload_fname('flash/', $xt);
move_uploaded_file ($tmp_name, $basedir . $fname);
$code = '[flash=' . $ow . ',' . $oh . ']http://' . $baseurl . $fname . '[/flash]';
} else {
$fname = get_upload_fname('image/', $xt);
$code = '[img width=' . $ow . ' height=' . $oh . ']http://' . $baseurl . $fname . '[/img]';
if (isset($_POST['thumb'])) {
do {
$nw = $ow;
$nh = $oh;
$ms = 196;
if ($nw > $ms) {
$nh = ($ms / $ow) * $oh;
$nw = $ms;
}
if ($nh > $ms) {
$nw = ($ms / $oh) * $ow;
$nh = $ms;
}
$nw = round($nw);
$nh = round($nh);
$om = @$cr($tmp_name);
if (!$om) break;
$im = imagecreatetruecolor($nw + 4, $nh + 15);
imagefill ($im, 0, 0, imagecolorallocate($im, 0, 0, 0));
imagecopyresampled ($im, $om, 2, 2, 0, 0, $nw, $nh, $ow, $oh);
imagestring ($im, 2, 2, $nh + 2, $ow . 'x' . $oh . ' - ' . $imagesize['mime'], imagecolorallocate($im, 255, 255, 255));
imagejpeg ($im, $basedir . 'thumb' . $fname, 85);
$code = '[url=http://' . $baseurl . $fname . '][img width=' . ($nw + 4) . ' height=' . ($nh + 15) . ']http://' . $baseurl . 'thumb' . $fname . '[/img][/url]';
} while (false);
}
if (!@move_uploaded_file($tmp_name, $basedir . $fname)) {
show_error ('Cannot copy image...');
break;
}
}
echo '
<center><font color=red>Copy the code below and paste it on your post</font>:
<div id="filefield">
<input type="text" style="width: 95%; text-align:center" value="' . htmlspecialchars($code) . '" onmouseover="this.focus();this.select();" />
</div>
<a href="./index_th.php">Upload more picture</a></center>';
} while (false);
} else {
echo '
<div id="upload" style="display:none"><center><b><font color="red">Uploading...</font></b><br /><br />Please be patient.</center></div>
<form enctype="multipart/form-data" action="./index_th.php" method="POST" onsubmit="this.style.display=\'none\';document.getElementById(\'upload\').style.display=\'block\';">
<center>
<div id="filefield">
<font color="red"><u><b>Upload Image</b></u> :: </font> <input type="hidden" name="MAX_FILE_SIZE" value="' . $maxsize . '" />
Send this file: <input size="36" name="userfile" type="file" />
<input type="submit" value="Upload" />
</div>
<label><input type="checkbox" name="thumb" />Create thumbnail</label><br />
<font color="red"><u>Supports</u></font> : .jpg .gif .png and .swf ; Maximum ' . floor($maxsize / 1024) . ' KB.<br />
</center>
</form>';
}
?>
</body>
</html>
**************************************************
แก้ตรงไหน ค่ะ ขอบคุณค่ะ
ลิงค์หัวข้อ:
http://dexmore.com/topic/8004