[B]old post: HI i have post this some where to get some one can help me out of this..
i donot know why the funtion uploadimg() doesn’t work.. not return any result.. .. please help urgent !! thanks
[B]Hi now i found solution just copy this to index.php then test call it like index.php?op=adminstory&sid=1 you use this if you use data mysql and the $sid is the id of reacord on table, if not you can only use uploadimg() or thumbls() my uncomment the switch($op).. sorry for my english.. ?
[B]index.php
[code=php]$sizecatnewshomeimg = 120;
$sizeimgskqa = 200;
$newsarticleimg = “left”;
$sizenewsarticleimg = 150;
$temp_path = “js/temp”;
$path = “js”;
$width = 600;
$max_size = 2097152;
define(‘INCLUDE_PATH’, ‘./’);
// the .INCLUDE_PATH. is setup in other file but it can be root of this file = “./” not important
switch($op) {
case “adminStory”:
adminStory($sid);
break;
case “PostAdminStory”:
postAdminStory($hometext, $images, $imgtext, $delpic);
break;
}
function adminStory() {
// have many code here but i make it now simple…
echo “<center><font class=”option”><b>”._ADDARTICLE.”</b></font></center><br>”
.”<form enctype=”multipart/form-data” action=”index.php” method=”post”>”;
echo “<br><br><b>”._STORYTEXT.”</b><br>”
.”<textarea wrap=”virtual” cols=”100″ rows=”15″ name=”hometext”>$hometext</textarea><br><br>”
.”<b>”._EXTENDEDTEXT.”</b><br>”;
////////images for stories
echo “<br><br><b>”._STPIC.”:</b> ”
.”<input name=”userfile” type=”file”><br><br>”
.”<b>”._IMGTEXT.”</b>: <input type=”text” name=”imgtext” value=”” size=”44″><br>”;
if ($images != “”) {
echo “<b>”._DELSTPIC.”:</b> “;
echo “<input type=”checkbox” name=”delpic” value=”yes”> <a href=”../$path/$images” target=”_blank”>$images</a><br><br>”;
}
echo “: 00<br><br>”
.”<select name=”op”>”
.”<option value=”PreviewAdminStory” selected>”._PREVIEWSTORY.”</option>”
.”<option value=”PostAdminStory”>”._POSTSTORY.”</option>”
.”</select>”
.”<input type=”submit” value=””._OK.””></form>”;
}
function postAdminStory($hometext, $images, $imgtext, $delpic) {
global $max_size, $width, $height, $path, $sizenewsarticleimg;
/// call the funtion to process the imagages before insert data..
$images = @uploadimg($images, $delpic, 1, $sizenewsarticleimg, $path);
if(!file_exists(“”.INCLUDE_PATH.””.$path.”/”.$images.””)) { $images=””; }
if($images == “”) $imgtext = “”;
echo “$hometext”;
echo “$images”;
echo “$imgtext”;
// this will be used for enter mysql data
// mysql_query(“insert into stories values (NULL, ‘$hometext’, ‘$images’, ‘$imgtext’)”);
}
/// the $delpic using to check box incase want to delete the exiting images on data and change it to ohter images upload file( yes/no)
function uploadimg($images, $delpic, $thumb, $thumb_width, $upath) {
global $max_size, $width, $sizeimgskqa;
if ($delpic == “yes”) {
@unlink(“”.INCLUDE_PATH.””.$upath.”/”.$images.””);
@unlink(“”.INCLUDE_PATH.””.$upath.”/small_”.$images.””);
$images = “”;
}
if (is_uploaded_file($_FILES[‘userfile’][‘tmp_name’])) {
@unlink(“”.INCLUDE_PATH.””.$upath.”/”.$images.””);
@unlink(“”.INCLUDE_PATH.””.$upath.”/small_”.$images.””);
$images = “”;
$realname = $_FILES[‘userfile’][‘name’];
$file_size = $_FILES[‘userfile’][‘size’];
$file_type = $_FILES[‘userfile’][‘type’];
$f_name = end(explode(“.”, $realname));
$f_extension = strtolower($f_name);
$loaiimg_ext = array(“gif”,”jpg”,”jpeg”,”pjpeg”,”png”,”bmp”);
$loaiimg_mime = array(“image/gif”, “image/pjpeg”, “image/jpeg”, “image/png”, “image/bmp”);
if ($file_size > $max_size) {
info_exit(“<br><br><center>”._EROR1.” “.$file_size.” “._EROR2.” $max_size byte.<br><br>”._GOBACK.”</center><br><br>”);
}
if(!in_array($file_type,$loaiimg_mime) || !in_array($f_extension,$loaiimg_ext)) {
info_exit(“<br><br><center>”._EROR6.”<br><br>”._GOBACK.”</center><br><br>”);
}
$datakod = date(U);
$picname = “”.$datakod.”.nv.”.$f_extension.””;
if(! @copy($_FILES[‘userfile’][‘tmp_name’], “”.INCLUDE_PATH.””.$upath.”/”.$picname.””) ) {
if (! move_uploaded_file($_FILES[‘userfile’][‘tmp_name’], “”.INCLUDE_PATH.””.$upath.”/”.$picname.””)) {
info_exit(“<br><br>”._UPLOADFAILED.”<br>”);
}
}
if (file_exists(“”.INCLUDE_PATH.””.$upath.”/”.$picname.””)) {
$images = $picname;
if ($f_extension == “jpg” AND extension_loaded(“gd”)) {
$size = @getimagesize(“”.INCLUDE_PATH.””.$upath.”/”.$images.””);
$thc = 0;
if ($size[0] > $width) {
$thc = 1; $sizemoi = $width;
} elseif($size[0] > $thumb_width AND $size[0] < ($thumb_width+20)) {
$thc = 1; $sizemoi = $thumb_width;
}
if ($thc == 1) {
$src_img= ImageCreateFromJpeg(“”.INCLUDE_PATH.””.$upath.”/”.$images.””);
$src_width= ImagesX($src_img);
$src_height= ImagesY($src_img);
$dest_width = $sizemoi;
$dest_height = $src_height/($src_width/$dest_width);
$dest_img=ImageCreateTrueColor($dest_width, $dest_height);
ImageCopyResampled($dest_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
ImageJpeg($dest_img, “”.INCLUDE_PATH.””.$upath.”/”.$images.””, 90);
ImageDestroy($dest_img);
}
$size = @getimagesize(“”.INCLUDE_PATH.””.$upath.”/”.$images.””);
if($thumb==1 AND $size[0] > $thumb_width) {
$picname_thumb = “small_”.$picname.””;
if(! @copy($_FILES[‘userfile’][‘tmp_name’], “”.INCLUDE_PATH.””.$upath.”/”.$picname_thumb.””) ) {
@move_uploaded_file($_FILES[‘userfile’][‘tmp_name’], “”.INCLUDE_PATH.””.$upath.”/”.$picname_thumb.””);
}
if (file_exists(“”.INCLUDE_PATH.””.$upath.”/”.$picname_thumb.””)) {
$src_img= ImageCreateFromJpeg(“”.INCLUDE_PATH.””.$upath.”/”.$picname_thumb.””);
$src_width= ImagesX($src_img);
$src_height= ImagesY($src_img);
$dest_width = $thumb_width;
$dest_height = $src_height/($src_width/$dest_width);
$dest_img=ImageCreateTrueColor($dest_width, $dest_height);
ImageCopyResampled($dest_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
ImageJpeg($dest_img, “”.INCLUDE_PATH.””.$upath.”/”.$picname_thumb.””, 90);
ImageDestroy($dest_img);
}
}
}
}
}
// $images = “testreturn.gif”; // this test not return work
return($images);
}
function info_exit($info) {
include(“header.php”);
echo “<br><center><b>”.$info.”</b></center><br>”;
include(“footer.php”);
exit();
}