SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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???????

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    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???????
    In your code, probably.

    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

  3. #3
    SitePoint Member
    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">&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>

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    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

  5. #5
    SitePoint Member
    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);
        }
    }

    ?>

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    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
    To:
    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
    Of course, more than one upload in one second (which is very possible) will cause an overwrite. Maybe something like:
    PHP Code:
    do{
        
    $this->new_name md5(rand());
    }while(
    file_exists($this->_upload_dir $this->new_name)); 
    This will help with combating overwriting a file, though hypothetically isn't totally strong because of race conditions.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok. lemme try this

  8. #8
    SitePoint Member
    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

  9. #9
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    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,
    Jake
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  10. #10
    SitePoint Member
    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

  11. #11
    SitePoint Member
    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????

  12. #12
    SitePoint Evangelist ferrari_chris's Avatar
    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;
    to this:
    Code PHP:
    $this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '', $_SERVER['PHP_SELF']).$this->_upload_dir.$this->new_name;
    At the end of the line, I got rid of the slash before the name of the file.

  13. #13
    SitePoint Member
    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

  14. #14
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    --------solved-------


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •