...

View Full Version : php or mysql problem??



gspabla
05-10-2009, 07:50 PM
the main problem is when a user uploads a photo to my site, the script converts the file name to something like 863d56ec9a75c15fbad89e8c046f43e1.jpg, and storing this file name to mysql database, and everything was doing fine.
but now when i try to upload a pic, after uploading the pic is not appearing coz the entry now in database is like http://www.sitename.com/memphoto2//5b06e1969ac7c2be6d9872feb7d739adjpg
(note extra things like site link, foldername, double back slash, and no dot before jpg in the last)

my hosting provider told me that they re-installed or upgraded GD Library (and may be something else) on server 2-3 days back.

and i havnt change any code or anything in site from 15 days
so what do u think where the problem is???????

bdl
05-10-2009, 08:16 PM
Can you show us the relevant portion of the PHP script that formats the file name and stores it in the database? Have you confirmed in your database itself that the values are like '863d56ec9a75c15fbad89e8c046f43e1.jpg'? What exactly is stored in the database?

gspabla
05-10-2009, 09:51 PM
yes i have confirmed, the file name of the uploaded image(in server/folder), is stored in the database
the code is:

<?php include("memprotect.php"); ?>
<?php include("config.php"); ?>

<?php
require 'php4upload.class.php';

if($_GET['Choice']=="1")
{
require 'Photouploddir1.php';
}
elseif ($_GET['Choice']=="2")
{
require 'Photouploddir2.php';
}
elseif ($_GET['Choice']=="3")
{
require 'Photouploddir3.php';
}



$im = new imageupload();
if ($_POST['__upload'])
{
header('location: '.'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']));
}
?>




<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $info['Title']; ?></title>
<meta name="Description" content="<?php echo $info['Description']; ?>">
<meta name="keywords" content="<?php echo $info['Keywords']; ?>">
<LINK href="style.css" rel="stylesheet" type="text/css">
</HEAD>

<style type="text/css">
body {
margin:0;
font-family:Verdana, arial, sans-serif;
font-size:12px;
}
div.wrapper {
margin:0 auto;
padding:5px;
width:620px;
border:1px solid #35528F;
}
h1 {
padding:8px;
margin:0px;
}
div.errors {
color:#FF0000;
}
ul {
list-style:none;
padding:5px;
}
ul li {
display:inline;
padding-right:12px;
}
p.footer {
clear:both;
text-align:center;
font-size:10px;
}
div.block {
float:left;
width:300px;
}
div.errors {
color:red;
}
</style>



<BODY class="body">



<DIV align="center">
<TABLE width="780" border="0" align="center" cellpadding="0" cellspacing="0" class="BlueTborder">
<!--DWLayoutTable-->

<TR>
<TD colspan="2"><?php include("topmenu.php");?></TD>
</TR>
<TR bgcolor="#FFFFFF">
<TD colspan="2" valign="top">



<!-- START LEFT PART -->
<DIV align="center">
<TABLE width="100%" border="0" cellpadding="0" cellspacing="0">
<TR>
<TD width="180" height="303" valign="top" bgcolor="#F5F5F5">
<?php include("left.php");?>
<?php include("leftbanner.php");?>
</TD>
<TD valign="top"><br>
<table width="97%" height="20" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="37%" background="pics/heading_bg.gif"><div align="left">&nbsp;&nbsp;<span class="bodysg">Photo Upload </span></div></td>
<td width="63%">&nbsp;</td>
</tr>
</table>
<table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" class="submenubox">
<tr>
<td>
<form method="post" enctype="multipart/form-data" action="<?=$im->path?>">
<table width="97%" border="0" align="center" cellpadding="3" cellspacing="3">
<tr>
<td colspan="2">Add Your photo : Choice-1<br>
Acceptable Formats : <span class="Alert">GIF</span> and <span class="Alert">JPG</span>. </td>
</tr>

<tr>
<td colspan="2"><p class="normaltext">&nbsp;</p></td>
</tr>
<tr>
<td width="23%">Select your Photo :</td>
<td width="77%"><input name="__upload" type="file" class="addtextfiled" size="35" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="submit" type="submit" class="afterloglightyellow2" value="Upload" /></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
</table>
</form>
<table width="97%" border="0" align="center">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>

<div class="block">
<?
if ($im->_im_status == true)
{

include('dbconnect.php');

$strid=$_SESSION['username'];



if($_GET['Choice']=="1")
{
$update1 = mysql_query("update register set Photo1='$im->imgurl' where MatriID='$strid'")
or die("Could not update data because ".mysql_error());

print "<script>";
print " self.location='photouploadconfirm.php?choice=1';"; // Comment this line if you don't want to redirect
print "</script>";

}
elseif ($_GET['Choice']=="2")
{
$update2 = mysql_query("update register set Photo2='$im->imgurl' where MatriID='$strid'")
or die("Could not update data because ".mysql_error());

print "<script>";
print " self.location='photouploadconfirm.php?choice=2';"; // Comment this line if you don't want to redirect
print "</script>";

}
elseif ($_GET['Choice']=="3")
{
$update3 = mysql_query("update register set Photo3='$im->imgurl' where MatriID='$strid'")
or die("Could not update data because ".mysql_error());

print "<script>";
print " self.location='photouploadconfirm.php?choice=3';"; // Comment this line if you don't want to redirect
print "</script>";
}




//echo '<h2>Upload Successful!</h2>';

//print '<a href="'.$im->imgurl.'">Photo </a>';
//print '<br>';
//print "$im->imgurl" ;
}
elseif (!empty($im->errorStr))
{
echo '<div class="errors">'.$im->errorStr.'</div>';
}

?>
</div>
</td>
</tr>
</table>

<p>&nbsp;</p>
</td>
</tr>
</table>
<p>&nbsp;</p></TD>
</TR>
</TABLE>

</DIV>
<!-- END LEFT PART -->



</TD>
</TR>

<TR>
<TD><?php include("footer.php");?></TD>
</TR>
<TR>

</TR>
<TR>

</TR>
</TABLE>

</DIV>




</BODY>
</HTML>

bdl
05-10-2009, 11:13 PM
1) It's a mess.
2) None of that shows where the file is uploaded or where the filename is created. I assume this is encapsulated within the 'imageupload' class.

Is this your own code? Or someone else's that you need help with?

gspabla
05-10-2009, 11:37 PM
someone else's code
here is the code from file php4upload.class.php

<?php
/*

- PHP4 Image upload script

*/

class imageupload
{
//pblic variables
var $path = '';
var $errorStr = '';
var $imgurl = '';

//private variables
var $_errors = array();
var $_params = array();
var $_lang = array();
var $_maxsize = 1048576;

var $_im_status = false;

//public methods
function imageupload ()
{
//require 'photouploadconfig.php';

if($_GET['Choice']=="1")
{
//require 'Photouploddir1.php';
//include 'Photouploddir1.php';


$title = 'PHP4 Image Upload';

$types = array('jpg', 'gif', 'png');
$maxsize = 1024*1024;

$upload_dir = 'memphoto1/';

//language
$lang['E_TYPE'] = 'Wrong image type.';
$lang['E_SIZE'] = 'File seze is not acceptable.';

}
elseif ($_GET['Choice']=="2")
{
//require 'Photouploddir2.php';
include 'Photouploddir2.php';
}
elseif ($_GET['Choice']=="3")
{
//require 'Photouploddir3.php';
include 'Photouploddir3.php';
}
elseif ($_GET['horoschoice']=="1")
{
//require 'horosuploaddir.php';
include 'horosuploaddir.php';
}

$this->_types = $types;
$this->_lang = $lang;
$this->_upload_dir = $upload_dir;
$this->_maxsize = $maxsize;

$this->path = $PHP_SELF;

if (is_array($_FILES['__upload']))
{
$this->_params = $_FILES['__upload'];
if (function_exists('exif_imagetype'))
$this->_doSafeUpload();
else
$this->_doUpload();

if (count($this->_errors) > 0)
$this->_errorMsg();
}
}

function allowTypes ()
{
$str = '';
if (count($this->_types) > 0) {
$str = 'Allowed types: (';
$str .= implode(', ', $this->_types);
$str .= ')';
}

return $str;
}

// private methods
function _doSafeUpload ()
{
preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches);
if (is_array($this->_types) && exif_imagetype($this->_params['tmp_name']) && in_array(strtolower($matches[1]), $this->_types))
{
if ($this->_params['size'] > $this->_maxsize)
$this->_errors[] = $this->_lang['E_SIZE'];
else
$this->_im_status = true;

if ($this->_im_status == true)
{
$ext = substr($this->_params['name'], -4);
$this->new_name = md5(time()).$ext;

move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name);

$this->imgurl =$this->new_name;

//$this->imgurl = .$this->new_name;


}
}
else
$this->_errors[] = $this->_lang['E_TYPE'];
}

function _doUpload ()
{
preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches);
if(in_array(strtolower($matches[1]), $this->_types))
{
if ($this->_params['size'] > $this->_maxsize)
$this->_errors[] = $this->_lang['E_SIZE'];
else
$this->_im_status = true;

if ($this->_im_status == true)
{
$ext = substr($this->_params['name'], -3);
$this->new_name = md5(time()).$ext;

move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name);

$this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.'/'.$this->new_name;

//$this->imgurl = ''.$this->_upload_dir.''.$this->new_name;
//$this->imgurl = ''.$this->new_name;

//$this->imgurl = $this->_upload_dir.'/'.$this->new_name;

}
}
else
$this->_errors[] = $this->_lang['E_TYPE'];
}

function _errorMsg()
{
$this->errorStr = implode('<br />', $this->_errors);
}
}

?>

venegal
05-10-2009, 11:58 PM
Well it certainly looks like somebody has messed with this class. How about you change it to the way it was?

gspabla
05-11-2009, 12:07 AM
i have not changed the code, it was running fine
but suddenly the problem arrived 2 days back
i/no one has changed anything from last 15 days in the code

please help me :(

venegal
05-11-2009, 12:26 AM
What can I tell you. Have a look at this code segment here:


if ($this->_im_status == true)
{
$ext = substr($this->_params['name'], -3);
$this->new_name = md5(time()).$ext;

move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name);

$this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.'/'.$this->new_name;

//$this->imgurl = ''.$this->_upload_dir.''.$this->new_name;
//$this->imgurl = ''.$this->new_name;

//$this->imgurl = $this->_upload_dir.'/'.$this->new_name;

}


Unlike the rest, it is not properly indented, and there are 4 versions of the same line, 3 of them commented out. And, surprise, the one completely unindented one, which is not commented out, is exactly the one causing the problem.

Now, it's probable that the server changes resulted in exif not being enabled, which in turn causes the class to call a different private method (the messed up one), but someone, sometime definitely meddled with your class, believe you me.

Change the above code to


if ($this->_im_status == true)
{
$ext = substr($this->_params['name'], -4);
$this->new_name = md5(time()).$ext;

move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name);

$this->imgurl =$this->new_name;

}


(this is code from the other private method) and see if it does what you expect it to do.

gspabla
05-11-2009, 12:31 AM
ok lemme try this

gspabla
05-11-2009, 12:56 AM
oh bro thanx, it worked
u r a gem
5* 2u



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum