Jump to content

A PHP-Fusion Modification


MTGap

Recommended Posts

I'm attempting to skip ahead in PHP-Fusion and submit an image directly instead of to the submissions db where an admin has to approve it to be in the photo gallery. However when I'm actually submitting an image this is what I get:

 

Notice: Undefined variable: origimage in /home/troop1/public_html/includes/photo_functions_include.php on line 28

 

Warning: imagesx(): supplied argument is not a valid Image resource in /home/troop1/public_html/includes/photo_functions_include.php on line 28

 

Notice: Undefined variable: origimage in /home/troop1/public_html/includes/photo_functions_include.php on line 29

 

Warning: imagesy(): supplied argument is not a valid Image resource in /home/troop1/public_html/includes/photo_functions_include.php on line 29

 

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/troop1/public_html/includes/photo_functions_include.php on line 51

 

Notice: Undefined variable: origimage in /home/troop1/public_html/includes/photo_functions_include.php on line 52

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/troop1/public_html/includes/photo_functions_include.php on line 52

 

The submit.php that I modified:

} elseif ($_GET['stype'] == "p") {
if (isset($_POST['submit_photo'])) {
	require_once INCLUDES."photo_functions_include.php";
	define("SAFEMODE", @ini_get("safe_mode") ? true : false);
	$error = "";
	$photo_file = ""; $photo_thumb1 = ""; $photo_thumb2 = "";
	$photo_title = stripinput($_POST['photo_title']);
	$photo_description = stripinput($_POST['photo_description']);
	$album_id = isnum($_POST['album_id']) ? $_POST['album_id'] : "0";
	if (is_uploaded_file($_FILES['photo_pic_file']['tmp_name'])) {
		$photo_types = array(".gif",".jpg",".jpeg",".png");
		$photo_pic = $_FILES['photo_pic_file'];
		$photo_name = strtolower(substr($photo_pic['name'], 0, strrpos($photo_pic['name'], ".")));
		$photo_ext = strtolower(strrchr($photo_pic['name'],"."));
		$photo_dest = PHOTOS.(!SAFEMODE ? "album_".$album_id."/" : "");
		$photo_file = image_exists($photo_dest, $photo_name.$photo_ext);
		$imagefile = @getimagesize($photo_dest.$photo_file);

		$photo_thumb1 = image_exists($photo_dest, $photo_name."_t1".$photo_ext);
		createthumbnail($imagefile[2], $photo_dest.$photo_file, $photo_dest.$photo_thumb1, $settings['thumb_w'], $settings['thumb_h']);
		if ($imagefile[0] > $settings['photo_w'] || $imagefile[1] > $settings['photo_h']) {
			$photo_thumb2 = image_exists($photo_dest, $photo_name."_t2".$photo_ext);
			createthumbnail($imagefile[2], $photo_dest.$photo_file, $photo_dest.$photo_thumb2, $settings['photo_w'], $settings['photo_h']);
		}
		$photo_order = dbresult(dbquery("SELECT MAX(photo_order) FROM ".DB_PHOTOS." WHERE album_id='$album_id'"), 0) + 1;
		if (!preg_match("/^[-0-9A-Z_\[\]]+$/i", $photo_name)) {
			$error = 1;
		} elseif ($photo_pic['size'] > $settings['photo_max_b']){
			$error = 2;
		} elseif (!in_array($photo_ext, $photo_types)) {
			$error = 3;
		} else {
			$photo_file = image_exists($photo_dest, $photo_name.$photo_ext);
			move_uploaded_file($photo_pic['tmp_name'], $photo_dest.$photo_file);
			chmod($photo_dest.$photo_file, 0644);
			$imagefile = @getimagesize($photo_dest.$photo_file);
			if (!verify_image($photo_dest.$photo_file)) {
				$error = 3;
				unlink($photo_dest.$photo_file);
			} elseif ($imagefile[0] > $settings['photo_max_w'] || $imagefile[1] > $settings['photo_max_h']) {
				$error = 4;
				unlink($photo_dest.$photo_file);
			} else {
				$submit_info['photo_file'] = $photo_file;
			}
		}
	}
	add_to_title($locale['global_200'].$locale['570']);
	opentable($locale['570']);
	if (!$error) {
		$result = dbquery("INSERT INTO ".DB_PHOTOS." (album_id, photo_title, photo_description, photo_filename, photo_thumb1, photo_thumb2, photo_datestamp, photo_user, photo_views, photo_order, photo_allow_comments, photo_allow_ratings) VALUES ('$album_id', '$photo_title', '$photo_description', '$photo_file', '$photo_thumb1', '$photo_thumb2', '".time()."', '".$data['submit_user']."', '0', '$photo_order', '1', '1')");
		echo "<div style='text-align:center'><br />\n".$locale['580']."<br /><br />\n";
		echo "<a href='submit.php?stype=p'>".$locale['581']."</a><br /><br />\n";
		echo "<a href='index.php'>".$locale['412']."</a><br /><br />\n</div>\n";
	} else {
		echo "<div style='text-align:center'><br />\n".$locale['600']."<br /><br />\n";
		if ($error == 1) { echo $locale['601']; }
		elseif ($error == 2) { echo sprintf($locale['602'], $settings['photo_max_b']); }
		elseif ($error == 3) { echo $locale['603']; }
		elseif ($error == 4) { echo sprintf($locale['604'], $settings['photo_max_w'], $settings['photo_max_h']); }
		echo "<br /><br />\n<a href='submit.php?stype=p'>".$locale['581']."</a><br /><br />\n</div>\n";
	}
	closetable();
} else {
	$opts = "";
	add_to_title($locale['global_200'].$locale['570']);
	opentable($locale['570']);
	$result = dbquery("SELECT * FROM ".DB_PHOTO_ALBUMS." WHERE ".groupaccess("album_access")." ORDER BY album_title");
	if (dbrows($result)) {
		while ($data = dbarray($result)) $opts .= "<option value='".$data['album_id']."'>".$data['album_title']."</option>\n";
		echo $locale['620']."<br /><br />\n";
		echo "<form name='submit_form' method='post' action='".FUSION_SELF."?stype=p' enctype='multipart/form-data' onsubmit='return validatePhoto(this);'>\n";
		echo "<table cellpadding='0' cellspacing='0' class='center'>\n<tr>\n";
		echo "<td class='tbl'>".$locale['621']."</td>\n";
		echo "<td class='tbl'><input type='text' name='photo_title' maxlength='100' class='textbox' style='width:250px;' /></td>\n";
		echo "</tr>\n<tr>\n";
		echo "<td valign='top' class='tbl'>".$locale['622']."</td>\n";
		echo "<td class='tbl'><textarea name='photo_description' cols='60' rows='5' class='textbox' style='width:250px;'></textarea></td>\n";
		echo "</tr>\n<tr>\n";
		echo "<td valign='top' class='tbl'>".$locale['623']."</td>\n";
		echo "<td class='tbl'><input type='file' name='photo_pic_file' class='textbox' style='width:250px;' /><br />\n";
		echo "<span class='small2'>".sprintf($locale['624'], parsebytesize($settings['photo_max_b']), $settings['photo_max_w'], $settings['photo_max_h'])."</span></td>\n";
		echo "</tr>\n<tr>\n";
		echo "<td class='tbl'>".$locale['625']."</td>\n";
		echo "<td class='tbl'><select name='album_id' class='textbox'>\n$opts</select></td>\n";
		echo "</tr>\n<tr>\n";
		echo "<td align='center' colspan='2' class='tbl'><br />\n";
		echo "<input type='submit' name='submit_photo' value='".$locale['626']."' class='button' />\n</td>\n";
		echo "</tr>\n</table>\n</form>\n";
	} else {
		echo "<div style='text-align:center'><br />\n".$locale['551']."<br /><br />\n</div>\n";
	}
	closetable();
}
}

 

Here's the photo_functions include:

 

<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2008 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: photo_functions_include
| Author: Nick Jones (Digitanium)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
if (!defined("IN_FUSION")) { die("Access Denied"); }

function createthumbnail($filetype, $origfile, $thumbfile, $new_w, $new_h) {

global $settings;

if ($filetype == 1) { $origimage = imagecreatefromgif($origfile); }
elseif ($filetype == 2) { $origimage = imagecreatefromjpeg($origfile); }
elseif ($filetype == 3) { $origimage = imagecreatefrompng($origfile); }

$old_x = imagesx($origimage);
$old_y = imagesy($origimage);

if ($old_x > $new_w || $old_y > $new_h) {
	if ($old_x < $old_y) {
		$thumb_w = round(($old_x * $new_h) / $old_y);
		$thumb_h = $new_h;
	} elseif ($old_x > $old_y) {
		$thumb_w = $new_w;
		$thumb_h = round(($old_y * $new_w) / $old_x);
	} else {
		$thumb_w = $new_w;
		$thumb_h = $new_h;
	}
} else {
	$thumb_w = $old_x;
	$thumb_h = $old_y;
}

if ($settings['thumb_compression'] == "gd1") {
	$thumbimage = imagecreate($thumb_w,$thumb_h);
	$result = imagecopyresized($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
} else {
	$thumbimage = imagecreatetruecolor($thumb_w,$thumb_h);
	$result = imagecopyresampled($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
}

touch($thumbfile);

if ($filetype == 1) { imagegif($thumbimage, $thumbfile); }
elseif ($filetype == 2) { imagejpeg($thumbimage, $thumbfile); }
elseif ($filetype == 3) { imagepng($thumbimage, $thumbfile); }
}

function image_exists($dir, $image) {
$i = 1;
$image_name = substr($image, 0, strrpos($image, "."));
$image_ext = strrchr($image, ".");
while (file_exists($dir.$image)) {
	$image = $image_name."_".$i.$image_ext;
	$i++;
}
return $image;
}
?>

 

And finally here is the original submit.php which did work correctly:

 

} elseif ($_GET['stype'] == "p") {
if (isset($_POST['submit_photo'])) {
	require_once INCLUDES."photo_functions_include.php";
	$error = "";
	$submit_info['photo_title'] = stripinput($_POST['photo_title']);
	$submit_info['photo_description'] = stripinput($_POST['photo_description']);
	$submit_info['album_id'] = isnum($_POST['album_id']) ? $_POST['album_id'] : "0";
	if (is_uploaded_file($_FILES['photo_pic_file']['tmp_name'])) {
		$photo_types = array(".gif",".jpg",".jpeg",".png");
		$photo_pic = $_FILES['photo_pic_file'];
		$photo_name = strtolower(substr($photo_pic['name'], 0, strrpos($photo_pic['name'], ".")));
		$photo_ext = strtolower(strrchr($photo_pic['name'],"."));
		$photo_dest = PHOTOS."submissions/";
		if (!preg_match("/^[-0-9A-Z_\[\]]+$/i", $photo_name)) {
			$error = 1;
		} elseif ($photo_pic['size'] > $settings['photo_max_b']){
			$error = 2;
		} elseif (!in_array($photo_ext, $photo_types)) {
			$error = 3;
		} else {
			$photo_file = image_exists($photo_dest, $photo_name.$photo_ext);
			move_uploaded_file($photo_pic['tmp_name'], $photo_dest.$photo_file);
			chmod($photo_dest.$photo_file, 0644);
			$imagefile = @getimagesize($photo_dest.$photo_file);
			if (!verify_image($photo_dest.$photo_file)) {
				$error = 3;
				unlink($photo_dest.$photo_file);
			} elseif ($imagefile[0] > $settings['photo_max_w'] || $imagefile[1] > $settings['photo_max_h']) {
				$error = 4;
				unlink($photo_dest.$photo_file);
			} else {
				$submit_info['photo_file'] = $photo_file;
			}
		}
	}
	add_to_title($locale['global_200'].$locale['570']);
	opentable($locale['570']);
	if (!$error) {
		$result = dbquery("INSERT INTO ".DB_SUBMISSIONS." (submit_type, submit_user, submit_datestamp, submit_criteria) VALUES ('p', '".$userdata['user_id']."', '".time()."', '".serialize($submit_info)."')");
		echo "<div style='text-align:center'><br />\n".$locale['580']."<br /><br />\n";
		echo "<a href='submit.php?stype=p'>".$locale['581']."</a><br /><br />\n";
		echo "<a href='index.php'>".$locale['412']."</a><br /><br />\n</div>\n";
	} else {
		echo "<div style='text-align:center'><br />\n".$locale['600']."<br /><br />\n";
		if ($error == 1) { echo $locale['601']; }
		elseif ($error == 2) { echo sprintf($locale['602'], $settings['photo_max_b']); }
		elseif ($error == 3) { echo $locale['603']; }
		elseif ($error == 4) { echo sprintf($locale['604'], $settings['photo_max_w'], $settings['photo_max_h']); }
		echo "<br /><br />\n<a href='submit.php?stype=p'>".$locale['581']."</a><br /><br />\n</div>\n";
	}
	closetable();
} else {
	$opts = "";
	add_to_title($locale['global_200'].$locale['570']);
	opentable($locale['570']);
	$result = dbquery("SELECT * FROM ".DB_PHOTO_ALBUMS." WHERE ".groupaccess("album_access")." ORDER BY album_title");
	if (dbrows($result)) {
		while ($data = dbarray($result)) $opts .= "<option value='".$data['album_id']."'>".$data['album_title']."</option>\n";
		echo $locale['620']."<br /><br />\n";
		echo "<form name='submit_form' method='post' action='".FUSION_SELF."?stype=p' enctype='multipart/form-data' onsubmit='return validatePhoto(this);'>\n";
		echo "<table cellpadding='0' cellspacing='0' class='center'>\n<tr>\n";
		echo "<td class='tbl'>".$locale['621']."</td>\n";
		echo "<td class='tbl'><input type='text' name='photo_title' maxlength='100' class='textbox' style='width:250px;' /></td>\n";
		echo "</tr>\n<tr>\n";
		echo "<td valign='top' class='tbl'>".$locale['622']."</td>\n";
		echo "<td class='tbl'><textarea name='photo_description' cols='60' rows='5' class='textbox' style='width:250px;'></textarea></td>\n";
		echo "</tr>\n<tr>\n";
		echo "<td valign='top' class='tbl'>".$locale['623']."</td>\n";
		echo "<td class='tbl'><input type='file' name='photo_pic_file' class='textbox' style='width:250px;' /><br />\n";
		echo "<span class='small2'>".sprintf($locale['624'], parsebytesize($settings['photo_max_b']), $settings['photo_max_w'], $settings['photo_max_h'])."</span></td>\n";
		echo "</tr>\n<tr>\n";
		echo "<td class='tbl'>".$locale['625']."</td>\n";
		echo "<td class='tbl'><select name='album_id' class='textbox'>\n$opts</select></td>\n";
		echo "</tr>\n<tr>\n";
		echo "<td align='center' colspan='2' class='tbl'><br />\n";
		echo "<input type='submit' name='submit_photo' value='".$locale['626']."' class='button' />\n</td>\n";
		echo "</tr>\n</table>\n</form>\n";
	} else {
		echo "<div style='text-align:center'><br />\n".$locale['551']."<br /><br />\n</div>\n";
	}
	closetable();
}
}

 

I know I'm not explaining this well, but hopefully someone can see what I'm trying to do.

Link to comment
https://forums.phpfreaks.com/topic/181323-a-php-fusion-modification/
Share on other sites

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.