/    Sign up×
Community /Pin to ProfileBookmark

dynamic upload images creator auto resize and checking if images exiting.. not work!!

[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]

[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]
[B]index.php[/B] ?

[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();
}
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@sitehatcheryAug 09.2006 — 
switch($op) {

case "adminStory":

adminStory($sid);

break;

case "PostAdminStory":

postAdminStory($hometext, $images, $imgtext, $delpic);

break;

}
[/quote]


Are you even getting inside the switch function? I don't see where you have previously defined $op. If it has no value, none of the cases would be evaluated.

Secondly, $hometext, $images, $imgtext, and $delpic has not been defined so you are passing empty variables to the postAdminStory() function. The same is true for adminStory(). You may have not included the variable delarations in this post, but if they don't exist in your script, this would be a reason why the functions do not return anything - they were never reached in the first place.
Copy linkTweet thisAlerts:
@binhausauthorAug 10.2006 — Are you even getting inside the switch function? I don't see where you have previously defined $op. If it has no value, none of the cases would be evaluated.
[/QUOTE]

this original code have many swich inside and i just cut it more simple to post here. Normaly it will be called by [B]index.php?op=adminStory&sid=9[/B] . It have other some process to work with the swich $op and $sid you can test this that will run then show up the $hometext but not for $images

Secondly, $hometext, $images, $imgtext, and $delpic has not been defined so you are passing empty variables to the postAdminStory() function. The same is true for adminStory(). You may have not included the variable delarations in this post, but if they don't exist in your script, this would be a reason why the functions do not return anything - they were never reached in the first place.[/QUOTE]

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
Copy linkTweet thisAlerts:
@binhausauthorAug 14.2006 — done: atlast i found the problems..--->> small stupid bugs ony for get to put it in form ( enctype="multipart/form-data" )

[B]now i trying to use this with ajax and muti upload images .. any one have idea???[/B]
×

Success!

Help @binhaus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...