PDA

توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : ایجاد تصویر با php مشکل کد من چیه ؟



teztop
March 26th, 2012, 14:42
سلام دوستان
من یک اپلودر تصویر آجاکس دارم
می خوام به همراه عکسی که آپلود می شه یه تصویر بند انگشتی هم باهاش آپلود بشه
اما تصویر بند انگشتی درست نمی شه
کدشو هم کامل گذاشتم

<?php

// the below method only works if the wp-content file hasn't been moved from it's normal location (as will
//be possible in 2.6+
$load = '../../../../wp-load.php';
if (file_exists($load)){ //if it's WP-2.6
require_once($load);
}
else {
require_once('../../../../wp-config.php');
}



$today = getdate();
if ($today['month'] == "January"){
$today['month'] = "01";
}
elseif ($today['month'] == "February"){
$today['month'] = "02";
}
elseif ($today['month'] == "March"){
$today['month'] = "03";
}
elseif ($today['month'] == "April"){
$today['month'] = "04";
}
elseif ($today['month'] == "May"){
$today['month'] = "05";
}
elseif ($today['month'] == "June"){
$today['month'] = "06";
}
elseif ($today['month'] == "July"){
$today['month'] = "07";
}
elseif ($today['month'] == "August"){
$today['month'] = "08";
}
elseif ($today['month'] == "September"){
$today['month'] = "09";
}
elseif ($today['month'] == "October"){
$today['month'] = "10";
}
elseif ($today['month'] == "November"){
$today['month'] = "11";
}
elseif ($today['month'] == "December"){
$today['month'] = "12";
}

// Edit upload location here
$destination_path = ABSPATH . "wp-content/uploads/".$today['year']."/".$today['month']."/";
if (!file_exists($destination_path)){
$year_path = ABSPATH . "wp-content/uploads/".$today['year']."/";
if (!file_exists($year_path)){
mkdir($year_path, 0777);
mkdir($destination_path, 0777);
}
else{
mkdir($destination_path, 0777);
}
}
$result = 0;

$name = $_FILES['myfile']['name'];
$uploadedfile = $_FILES['myfile']['tmp_name'];

$name = strtolower($name);
preg_match("/(.*)\.(.*)/", $name, $matches);
$stem = $matches[1];
$extension = $matches[2];
$filetypes = array("jpg", "jpeg", "bmp", "gif", "png");

if (!in_array($extension, $filetypes)){
$user_path = "Not an allowed File type!"; ?>
<script language="javascript" type="text/javascript">window.parent.window.noUpload(<?php echo $result.", '".$user_path."'"; ?>);</script>
<?php die;
}

$t=0;
while (file_exists($destination_path . $name)) {
$name = $t.'_'.$name;
$t++;
}
$target_path = $destination_path . $name;
$user_path = get_option( 'siteurl' ) ."/wp-content/uploads/".$today['year']."/".$today['month']."/".$name;
$user_path2 = get_option( 'siteurl' ) ."/wp-content/uploads/".$today['year']."/".$today['month']."/thumb-".$name;

switch($extension){
case "gif":
$src = imagecreatefromgif($uploadedfile);
break;
case "jpg":
$src = imagecreatefromjpeg($uploadedfile);
break;
case "jpeg":
$src = imagecreatefromjpeg($uploadedfile);
break;
case "png":
$src = imagecreatefrompng($uploadedfile);
break;
}

// copy original image
copy($_FILES['myfile']['tmp_name'], $target_path);

// orignal image location
$write_image = $user_path;

// create first thumbnail image - resize original to 80 width x 80 height pixels
$newheight = ($height/$width)*80;
$newwidth = 80;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagealphablending($tmp, false);
imagesavealpha($tmp,true);
$transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefilledrectangle($tmp, 0, 0, $newwidth, $newheight, $transparent);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$ne wheight,$width,$height);

// write thumbnail to disk
$write_thumbimage = $user_path2;
switch($extension){
case "gif":
imagegif($tmp,$write_thumbimage);
break;
case "jpg":
imagejpeg($tmp,$write_thumbimage,100);
break;
case "jpeg":
imagejpeg($tmp,$write_thumbimage,100);
break;
case "png":
imagepng($tmp,$write_thumbimage);
break;
}

if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
$result = 1;

}

$imgNumb = "image".$_GET['img'];
imagedestroy($src);
imagedestroy($tmp);
?>

<script language="javascript" type="text/javascript">window.parent.window.noUpload(<?php echo $result.", '".$write_thumbimage."', '".$imgNumb."'"; ?>);</script>
<?php

?>