Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > PHP Development
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-10-2006, 10:44 AM   #1 (permalink)
binhaus
Junior Member
 
Join Date: Aug 2006
Posts: 3
Question dynamic upload images creator auto resize and checking if images exiting.. not work

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
index.php it can be call by /index.php?op=AdminStory&sid=6
i have cut down the code so some one can easy view and help me here..
PHP Code:
$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 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$images;
/// call the funtion to process the imagages before insert data..
//$images="";
    
if (!is_uploaded_file($_FILES['userfile']['tmp_name'])) { $aa"uploaded to tmp"; }
    
$images = @uploadimg($images$delpic1$sizenewsarticleimg$path);
    if(!
file_exists("".INCLUDE_PATH."".$path."/".$images."")) { $images=""; }
    if(
$images == ""$imgtext "";

echo 
"$aa";
echo 
"<br>hometext: $hometext";
echo 
"<br>imagesname: $images";
echo 
"<br>imagestext: $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$images;
    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_imgImageCreateFromJpeg("".INCLUDE_PATH."".$upath."/".$images."");
            
$src_widthImagesX($src_img);
            
$src_heightImagesY($src_img);
            
$dest_width $sizemoi;
            
$dest_height $src_height/($src_width/$dest_width);
            
$dest_img=ImageCreateTrueColor($dest_width$dest_height);
            
ImageCopyResampled($dest_img$src_img0000$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==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_imgImageCreateFromJpeg("".INCLUDE_PATH."".$upath."/".$picname_thumb."");
                    
$src_widthImagesX($src_img);
                    
$src_heightImagesY($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_img0000$dest_width$dest_height$src_width$src_height);
                    
ImageJpeg($dest_img"".INCLUDE_PATH."".$upath."/".$picname_thumb.""90);
                    
ImageDestroy($dest_img);
            }
        }
    }
    }
    }
//    $images = "testreturn"; //  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();


------------
notices that the $delpic is used when i going to edit my database by swich $op=editstory. it will be as the check box if some images exiting on the data.. so if i add the new article $delpic will be 'null' or 'No'.., if i tick it the $delpic will be "yes" which will be processed in funtion upload image when call $images = @uploadimg(..);
the the $hometext and $images and $imgtext is send to postadminstoy() when submit the form, The $imgtext = null incase $images = ""; they are returned from uploadimg() before submit the form..
please test it.. .. thank for any help!! i realy in urgent..!!
regards
binhaus is offline   Reply With Quote
Sponsored Links
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 04:42 PM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums