Hey Guys,
I have a script that runs fine on a local server (PHP 4.3.10) and a remote server (also 4.3.10) but on the clients server (4.3.5RC4) it gives me an undefined function error... very strange, heres the code;
**************************
**********
**********
**********
**********
****
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL &~E_NOTICE);
include('header.php');
include('menu.php');
include('../config.php');
function resampimagejpg($psize, $sourcefile, $pdestfile, $g_imgcomp) {
$g_srcfile=$sourcefile;
if(file_exists($sourcefile
)) {
//Get data from source image
$g_is=getimagesize($source
file);
$p = pathinfo($sourcefile);
switch ($p['extension']) {
case 'gif':
$img_src=imagecreatefromgi
f($sourcef
ile);
break;
case 'jpg':
case 'jpeg':
$img_src=imagecreatefromjp
eg($source
file);
break;
case 'png': // line 33, apparent errorneous line
$img_src=imagecreatefrompn
g($sourcef
ile);
break;
default:
return false; //Can't handle other formats
}
//Create preview sized image
if ($g_is[0] > $psize or $g_is[1] > $psize) { //Only shrink, don't enlarge to fit
$g_fw=$psize;
$g_fh=$psize;
if(($g_is[0]-$g_fw)>=($g_i
s[1]-$g_fh
)) {
$g_iw=$g_fw;
$g_ih=($g_fw/$g_is[0])*$g_
is[1];
} else {
$g_ih=$g_fh;
$g_iw=($g_ih/$g_is[1])*$g_
is[0];
}
$img_dst=imagecreatetrueco
lor($g_iw,
$g_ih);
imagecopyresampled($img_ds
t, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]);
} else { //Just copy the image
$img_dst = $img_src;
}
imageinterlace($img_dst, 1);
imagejpeg($img_dst, $pdestfile, $g_imgcomp);
imagedestroy($img_dst);
return true;
} else {
return false;
}
}
//Check that there was actually an upload before proceeding
if (count($_FILES) > 0 and array_key_exists('image', $_FILES)) {
if (is_uploaded_file($_FILES[
'image']['
tmp_name']
)) {
if ($_FILES['image']['name'] != '')
{
$pic_name = "1_" . date("d_m_Y_H_i") . "_" . $_FILES['image']['name'];
} else {
exit; //Can't really do anything if we don't have a filename
}
$uploaddir = '../images/phones/';
$thumbnaildir = '../images/phones/thumbs/'
;
$sourcefile = $uploaddir.$pic_name;
move_uploaded_file($_FILES
['image'][
'tmp_name'
], $sourcefile);
$pdestfile = "{$thumbnaildir}tn_{$pic_n
ame}";
$g_imgcomp = $img_comp;
$psize = $img_max_width;
resampimagejpg($psize, $sourcefile, $pdestfile, $g_imgcomp);
}
}
if ($dbc = @mysql_connect($db_host, $db_user, $db_pass)) {
if (!mysql_select_db($db_name
)) {
die('<p>Could not connect to the database because: <b>' . mysql_error() . '</b></p>');
}
} else {
die('<p>Could not connect to the database because: <b>' . mysql_error() . '</b></p>');
}
$query1 = "SELECT * from phone_man ORDER BY name" or die(mysql_error());
$r = mysql_query($query1) or die(mysql_error());
$row = mysql_fetch_assoc($r);
echo '<div class="main">';
echo '
<p><h1>Add a Phone</h1></p>';
if (!isset($_POST['submit']))
{
echo '
<form name="add_phone" method="post" action="phones_add.php" enctype="multipart/form-da
ta">
<table width="80%" border="0">
<tr>
<td width="100">Name:</td>
<td><input type="text" name="name" size="50" /></td>
</tr>
<tr>
<td width="100">Manufacturer:<
/td>
<td><select name="man">
<option value="Select...">Select..
.</option>
';
do {
echo'<option value="'.$row['name'].'">'
.$row['nam
e'].'</opt
ion>';
}
while($row = mysql_fetch_assoc($r));
echo '</select></td>
</tr>
<tr>
<td width="100">Features and Info:</td>
<td><textarea name="body" cols="50" rows="10"></textarea></td>
</tr>
<tr>
<td width="100">Image:</td>
<td><input type="file" name="image" /></td>
</tr>
<tr>
<td width="100">Price:</td>
<td><input type="text" name="price" size="50" /></td>
</tr>
<tr>
<td width="100">Network:</td>
<td><input type="radio" name="network" value="cdma" /> CDMA<br />
<input type="radio" name="network" value="gsm" /> GSM<br /></td>
</tr>
<tr>
<td width="100"><input type="submit" name="submit" value="Add Phone" /></td>
<td><input type="reset" name="reset" value="Clear Form" /></td>
</tr>
</table>
</form>';
}
if (isset($_POST['submit'])) {
$p_name = addslashes($_POST['name'])
;
$p_man = addslashes($_POST['man']);
$p_body = addslashes($_POST['body'])
;
$p_image = addslashes($pic_name);
$p_price = addslashes($_POST['price']
);
$p_network = addslashes($_POST['network
']);
$query = "INSERT into phones (name, body, image, price, man, network) VALUES ('{$p_name}', '{$p_body}' , '{$p_image}', '{$p_price}', '{$p_man}' , '{$p_network}')";
if (@mysql_query ($query)) {
header('Location: thanks.php');
} else {
echo 'An error occured while entering the data, the error was ' . mysql_error() . ' and the query was ' . $query . '';
}
}
echo '</div>';
ob_end_flush();
include('footer.php');
?>
**************************
**********
**********
**********
*********
The exact error is;
Fatal error: Call to undefined function: imagecreatefromjpeg() in /home/intouch/public_html/
admin/phon
es_add.php
on line 33
This is really urgent, any help is so muchly appreciated!!!!! :)
Christian