Jump to content

[SOLVED] Multi-Image Thumb Functions


Grimloch

Recommended Posts

Hello folks I'm back again. I'm right on the verge of solving the middle third of my 3 part equation for uploading multiple images to a classified ads script in PHP-Fusion7 CMS. The 3 part equation is:

1) Upload and save multiple images - works!

2) Generate and save thumbs for them - almost works.

3) Update db with image/thumb info - not tackled yet, don't know how.

 

Part 2:

Here is the code I have in place now that successfully uploads and saves multiple images.

 

function Add($cat, $title, $description, $url, $weeks, $owner, $owner_id)
{
global $adstext, $locale, $userdata, $settings, $db_prefix;
require_once INCLUDES."photo_functions_include.php";
    if(isset($_POST[save_ad])) {

$postdate = time();
$expiredate = $postdate + (3600 * 24 * $weeks);
$url = explode("http://", $url);
if ($url[1]=="")
{
	$myurl = "";
} else {
	$myurl ="$url[1]";
}
// Check if Category exist
if ($cat=="")
{
	echo "<br />";
	$mainlink = 1;
	menu($mainlink);
	echo "<br /><br />".$locale['CLS_0041']."<br />";
	exit();
}
// Check if Title exist
if ($title=="")
{
	echo "<br />";
	$mainlink = 1;
	menu($mainlink);
	echo "<br /><br />".$locale['CLS_0042']."<br />";
	exit();
}
// Check if ads text exist
if ($description=="")
{
	echo "<br />";
	$mainlink = 1;
	menu($mainlink);
	echo "<br /><br />".$locale['CLS_0043']."<br />";
	exit();
} 
// Check ads text length	
if (strlen($description) > $adstext) 
{
	echo "<br />";
	$mainlink = 1;
	menu($mainlink);
	echo "<br /><br />".$locale['CLS_0044'].": $adstext characters.<br />";
	exit();
} 
$title = addslashes($title);
$description = addslashes($description);
// ad image upload
while (list ($key, $value) = each($_FILES['adimg']['tmp_name']))
{
if (!empty ($value))
	$imagename = $_FILES['adimg']['name'][$key];
	$source = $_FILES['adimg']['tmp_name'][$key];
	$img_pic = $_FILES['imagename'];
	$img_name = strtolower(substr($img_pic['name'][$key], 0, strrpos($img_pic['name'][$key], ".")));
	$img_ext = strtolower(strrchr($img_pic['name'][$key],"."));
	$target = INFUSIONS.'classified_ads_panel/images/ads/'.$imagename;
	$thumbs = INFUSIONS.'classified_ads_panel/images/ads/thum/'.$imagename;
	$img_file = image_exists($target, $img_name.$img_ext);
	move_uploaded_file($source, $target);
		$imagefile = @getimagesize($target.$img_file);
		$thb = image_exists($target, $img_name."_t1".$img_ext);
		createthumbnail($imagefile[2], $thumbs.$img_file, $thumbs.$thb, $settings['thumb_w'], $settings['thumb_h']);
}
}
// end ad image upload

 

These are images of my ftp directory after upload:

 

Complete dir is: infusions/classified_ads_panel/images/ads/thum/

images/ads are main images and ads/thum are thumbnails

 

images_ads_dir.jpg

 

images_ads_thum_dir.jpg

 

As you can see its writing the thumb filenames but incorrectly and the files are empty. I've racked my brain trying to figure out what I have wrong in the code and just can't seem to get my head around it. Any help appreciated.

Link to comment
https://forums.phpfreaks.com/topic/181522-solved-multi-image-thumb-functions/
Share on other sites

...I am getting closer and closer. After much experimentation I determined that my $img_name and $img_ext 'strtolower' functions were not right and it was never separating the filenames into name,extension. Here is my code now:

 

// ad image upload
while (list ($key, $value) = each($_FILES['adimg']['tmp_name']))
{
if (!empty ($value))
	$imagename = $_FILES['adimg']['name'][$key];
	$source = $_FILES['adimg']['tmp_name'][$key];
	$img_name = strtolower(substr($imagename, 0, strrpos($imagename, ".")));
	$img_ext = strtolower(strrchr($imagename,"."));
	$target = INFUSIONS.'classified_ads_panel/images/ads/'.$imagename;
	$thumbs = INFUSIONS.'classified_ads_panel/images/ads/thum/';
	$img_file = image_exists($target, $img_name.$img_ext);
	move_uploaded_file($source, $target);
		$imagefile = @getimagesize($img_file);
		$thb = image_exists($target, $img_name."_t1".$img_ext);
		createthumbnail($imagefile[2], $thumbs.$img_file, $thumbs.$thb, $settings['thumb_w'], $settings['thumb_h']);
	}
}
// end ad image upload

 

And here is an image of my ftp dir after upload.

 

new_imgs_ads_thum_dir.jpg

 

The thumb function is now writing the correct filename but the files are still empty. Please, if anyone can see what I am doing wrong here I would be most greatful! Then I must solve the db update coding. Thanks in advance.

:shrug:

I am totally absolutely bewildered. Why is it that I can't seem to get any help here with my problem? No suggestions; no comments; no NOTHING! Is this problem too tough for anyone here? Is thing thing I am trying to accomplish an undo-able thing in PHP/MySQL? Since I've made some rather hasty and regrettable comments on previous posts, is it that no one wants to bother with me? Exactly what is the problem here? If no one can help PLEASE at least point me to where I CAN get some help.

Well, I don't really understand why but it's obvious to me now that I can no longer expect any help from anyone on this forum system. Thats too bad because I found it to be a valuable resource and may still read posts from time to time. But you won't be bothered by my requests for help anymore as it has become pointless. Thanks to everyone on here who DID help me; I appreciate it. So long.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.