Store images in database

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
DragonzInsanity
Registered User
Posts: 12
Joined: Mon May 08, 2017 8:49 pm

Store images in database

Post by DragonzInsanity »

Hello, I am not sure how to correctly code a specific part of this. I am trying to put in a specific url into the database. I am trying to format it so that when the user clicks on a specific button, it stores the image url, name, and id of the user.

Here is adopt.php:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

$user->session_begin();
if ($user->data['user_id'] == ANONYMOUS)
{
    login_box('', $user->lang['LOGIN']);
} 
$auth->acl($user->data);
$user->setup('viewforum');
require("adopttools.php");
require('conn.php');
$request->enable_super_globals();

/* Our visitor has picked an adoptable they want, its id is in $_REQUEST['id']. Find that
 * adoptable in adoptables.xml
 */
$adoptable=find_adoptable($_REQUEST['id']);


/* To randomly pick a variation from that adoptable, we're going have to do a little maths with
 * random numbers.
 *
 * First we find the sum of all the 'chance' attributes for this adoptable...
 */

$sum=0;
foreach ($adoptable->variation as $variation) {
	$sum=$sum + $variation['chance'];
}

/* Now we can generate a random number which goes from 0.0 to that sum. This will help us
 * pick a variation.
 */
$random=lcg_value()*$sum;

$sum=0;
foreach ($adoptable->variation as $variation) {
	$sum = $sum + $variation['chance'];
	
	if ($random <= $sum) {
		//Choose this variation
		$v_id= encrypt_variation($variation['id']);
		break;
	}
}

?>

<p><img src="simple.php?a=<?php echo $_REQUEST['id'];?>&amp;v=<?php echo $v_id;?>"></p>

<p>Thanks for adopting this pet! :). Use this code to display your pet on a webpage: (HTML code)</p>

<p><textarea cols="60" rows="2"><?php

echo "<a href='http://".$_SERVER['SERVER_NAME']."/'><img border='0' src='http://".$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF'])."/simple.php?a=".$_REQUEST['id']."&amp;v=$v_id'></a><br>
Owner's name: ".$_REQUEST['ownername']."<br>
Pet's name: ".$_REQUEST['petname'];

	$sql_ary = array(
		'id'		=> (int) $user->data['user_id'],
		'pet_url'	=> (char) $_REQUEST['image'],
		'pet_name'	=> (char) $_REQUEST['petname'],
	);
	// $table_prefix . 'user_pet_info
	$sql = 'INSERT INTO ' . 'user_pet_info ' . $db->sql_build_array('INSERT', $sql_ary);
	$db->sql_query($sql); 

?></textarea></p>

<p>Use this code to display your pet on a forum: (BBCode)</p>

<p><textarea cols="60" rows="2"><?php

echo "[url=http://".$_SERVER['SERVER_NAME']."/][img]http://".$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF'])."/simple.php?a=".$_REQUEST['id']."&amp;v=$v_id&amp;.jpg[/img][/url]
Owner's name: ".$_REQUEST['ownername']."
Pet's name: ".$_REQUEST['petname'];

?></textarea></p>

</body>
</html>
And this is adoptables.xml where all the images are defined as well as the odds of it choosing one image over the other.

Code: Select all

<adoptables>

<adoptable id="1">
	<variation id="1" chance="1.0">
		<age image="dogbaby.png" />
		<age date="2017-3-20" image="dogpuppyrare.png" />	
		<age date="2017-11-25" image="dogadultrare.png" />
	</variation>
	<variation id="2" chance="5.0">
		<age image="dogbaby.png" />
		<age date="2017-3-20" image="dogpuppy.png" />	
		<age date="2017-11-25" image="dogadult.png" />
	</variation>
</adoptable>

<adoptable id="2">
	<variation id="1" chance="1.0">
		<age image="ratbaby.png" />
		<age date="2017-7-27" image="ratadult.png" />
	</variation>
</adoptable>

</adoptables>
DragonzInsanity
Registered User
Posts: 12
Joined: Mon May 08, 2017 8:49 pm

Re: Store images in database

Post by DragonzInsanity »

?

Return to “phpBB Custom Coding”