SitePoint Sponsor |
|
User Tag List
Results 1 to 14 of 14
Thread: Php or mysql problem??
-
May 10, 2009, 11:47 #1
- Join Date
- Apr 2009
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Php or mysql problem??
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//5...2feb7d739adjpg
(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???????
-
May 10, 2009, 14:02 #2
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
so what do u think where the problem is???????
Can you post it here?Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
May 10, 2009, 14:06 #3
- Join Date
- Apr 2009
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
yes offcourse, but i havne change anything in the code from past few days
well the code is:
PHP Code:<?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"> <span class="bodysg">Photo Upload </span></div></td>
<td width="63%"> </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"> </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> </td>
<td><input name="submit" type="submit" class="afterloglightyellow2" value="Upload" /></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</form>
<table width="97%" border="0" align="center">
<tr>
<td> </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> </p>
</td>
</tr>
</table>
<p> </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>
-
May 10, 2009, 14:10 #4
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
It seems the problem lies in the ImageUpload class. Care to post it?
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
May 10, 2009, 14:16 #5
- Join Date
- Apr 2009
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
this is the content from file php4upload.class.php
PHP Code:<?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);
}
}
?>
-
May 10, 2009, 15:07 #6
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Try Changing:
PHP Code:$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;
PHP Code:$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;
PHP Code:do{
$this->new_name = md5(rand());
}while(file_exists($this->_upload_dir . $this->new_name));
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
May 10, 2009, 15:18 #7
- Join Date
- Apr 2009
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok. lemme try this
-
May 10, 2009, 15:27 #8
- Join Date
- Apr 2009
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok. the problem solved a little.
its now adding a dot before jpg now
but the
http://www.sitename.com/memphoto1//
is still the extra thing added in mysql before the fcb317005328d64b8d51c1ed5dac2604.jpg
please help me out i know u r trying
-
May 10, 2009, 15:38 #9
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Well, you now know the problem is in your code, now it's your turn to try and find the error.
For many reasons really. Firstly, you need to learn how to debug your code. Secondly, I'm heading to bed now and I don't have time to read through the code again
Good luck,
JakeJake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
May 10, 2009, 15:42 #10
- Join Date
- Apr 2009
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
okk. thanx jake for helping this much,
well im a fresher for this php and mysql, and i m not able to understands these codes now
so can u please check again when u wakeup or when u free???
goodnight for now, and thanx again for helping
hope to c u back soon
-
May 10, 2009, 15:44 #11
- Join Date
- Apr 2009
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
btw i m still in shock how a good running site can change its code itself???
nobody has ftp or any other details, only me
and i havnt touched anything in this site from few days
is it possible????
-
May 10, 2009, 15:51 #12
- Join Date
- Mar 2008
- Location
- NP, New Zealand
- Posts
- 576
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try changing this:
Code PHP:$this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '', $_SERVER['PHP_SELF']).$this->_upload_dir.'/'.$this->new_name;
Code PHP:$this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '', $_SERVER['PHP_SELF']).$this->_upload_dir.$this->new_name;
-
May 10, 2009, 16:04 #13
- Join Date
- Apr 2009
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hmm the problem is still the same just its single / rather than // before file name now
-
May 10, 2009, 16:57 #14
- Join Date
- Apr 2009
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
--------solved-------
Bookmarks