Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post

    resize image on php page

    hi

    i am making a page that displays profile picture.

    i have made a upload form that submits the info into the dater base and save the photo in to a file but when the user uploads the picture it could be any size and i know you can resize it then they upload but i am new to php.
    i look at some code and tries it but could not get it to work so i desided to let the picture be any size and then resize the picture one the page.

    but i have tried a few way i they did not work.

    so what i am asking is how do i resize the image on the php page.

    thanks alot
    Last edited by Inigoesdr; 02-28-2010 at 08:38 PM. Reason: Marked resolved

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,495
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    resampled reproduces it better than resized ... must be some sort of algorithm.

  • #5
    New Coder
    Join Date
    Feb 2010
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post

    Question confused

    ok first thanks for everys help but what is wrong with this is resizes to image but does not sumbit the infomation to the dater base

    PHP Code:

    <?php require_once('../Connections/mywigan.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }
    }

    $colname_Recordset1 "-1";
    if (isset(
    $_GET['MM_Username'])) {
      
    $colname_Recordset1 $_GET['MM_Username'];
    }
    mysql_select_db($database_mywigan$mywigan);
    $query_Recordset1 sprintf("SELECT * FROM `user` WHERE username = %s"GetSQLValueString($colname_Recordset1"text"));
    $Recordset1 mysql_query($query_Recordset1$mywigan) or die(mysql_error());
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 mysql_num_rows($Recordset1);
     



                
                
    error_reporting(0);

    $change="";
    $abc="";


     
    define ("MAX_SIZE","4000");
     function 
    getExtension($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }

     
    $errors=0;
      
     if(
    $_SERVER["REQUEST_METHOD"] == "POST")
     {
         
    $image =$_FILES["file"]["name"];
        
    $uploadedfile $_FILES['file']['tmp_name'];
         
     
         if (
    $image
         {
         
             
    $filename stripslashes($_FILES['file']['name']);
         
              
    $extension getExtension($filename);
             
    $extension strtolower($extension);
            
            
     if ((
    $extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
             {
            
                 
    $change='<div class="msgdiv">Unknown Image extension </div> ';
                 
    $errors=1;
             }
             else
             {

     
    $size=filesize($_FILES['file']['tmp_name']);


    if (
    $size MAX_SIZE*1024)
    {
        
    $change='<div class="msgdiv">You have exceeded the size limit!</div> ';
        
    $errors=1;
    }


    if(
    $extension=="jpg" || $extension=="jpeg" )
    {
    $uploadedfile $_FILES['file']['tmp_name'];
    $src imagecreatefromjpeg($uploadedfile);

    }
    else if(
    $extension=="png")
    {
    $uploadedfile $_FILES['file']['tmp_name'];
    $src imagecreatefrompng($uploadedfile);

    }
    else 
    {
    $src imagecreatefromgif($uploadedfile);
    }

    echo 
    $scr;

    list(
    $width,$height)=getimagesize($uploadedfile);


    $newwidth=60;
    $newheight=($height/$width)*$newwidth;
    $tmp=imagecreatetruecolor($newwidth,$newheight);


    $newwidth1=25;
    $newheight1=($height/$width)*$newwidth1;
    $tmp1=imagecreatetruecolor($newwidth1,$newheight1);

    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

    imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);


    $filename "../images/"$_FILES['file']['name'];

    $filename1 "../images/thumbs/"$_FILES['file']['name'];



    imagejpeg($tmp,$filename,100);

    imagejpeg($tmp1,$filename1,100);

    imagedestroy($src);
    imagedestroy($tmp);
    imagedestroy($tmp1);
    }}

    }

    //If no errors registred, print the success message
     
    if(isset($_POST['Submit']) && !$errors
     {
     
    // Gather all required data
           
           
    $dbLink = new mysqli('localhost''root''password''mywigan');
            if(
    mysqli_connect_errno()) {
                die(
    "MySQL connection failed: "mysqli_connect_error());
            }
            
    $data $dbLink->real_escape_string($filename);
           
            
    $username =  $_POST['hiddenField'];
     
            
    // Create the SQL query
            
    $query "
                INSERT INTO `profile_picture` (
                     `file`, `username`
                )
                VALUES (
                  '{$data}', '{$username}'
                )"
    ;
       
    // mysql_query("update {$prefix}users set img='$big',img_small='$small' where user_id='$user'");
         
    $change=' <div class="msgdiv">Image Uploaded Successfully!</div>';
     }
     
     
    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
        <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <meta content="en-us" http-equiv="Content-Language">

        <title>picture demo</title>
        
       <link href=".css" media="screen, projection" rel="stylesheet" type="text/css">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery_002.js"></script>
    <script type="text/javascript" src="js/displaymsg.js"></script>
    <script type="text/javascript" src="js/ajaxdelete.js"></script>
        
         
      <style type="text/css">
      .help
    {
    font-size:11px; color:#006600;
    }
    body {
         color: #000000;
     background-color:#999999 ;
        background:#999999 url(<?php echo $user_row['img_src']; ?>) fixed repeat top left;
        
        
        font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; 
        
        }
            .msgdiv{
        width:759px;
    padding-top:8px;
    padding-bottom:8px;
    background-color: #fff;
    font-weight:bold;
    font-size:18px;-moz-border-radius: 6px;-webkit-border-radius: 6px;
    }
    #container{width:763px;margin:0 auto;padding:3px 0;text-align:left;position:relative; -moz-border-radius: 6px;-webkit-border-radius: 6px; background-color:#FFFFFF }
    </style>

      </head><body>
         <div align="center" id="err">
    <?php echo $change?>  </div>
       <div id="space"></div>
       
     
      
      
      
      <div id="container" >
        
       <div id="con">
       
          
          
            <table width="502" cellpadding="0" cellspacing="0" id="main">
              <tbody>
                <tr>

                  <td width="500" height="238" valign="top" id="main_right">
                 
                  <div id="posts">
                  &nbsp;&nbsp;&nbsp;&nbsp;<img src="<?php echo $filename?>" />  &nbsp;&nbsp;&nbsp;&nbsp;<img src="<?php echo $filename1?>"  />
                    <form method="post" action="" enctype="multipart/form-data" name="form1">
                    <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
                   <tr><Td style="height:25px">&nbsp;</Td></tr>
            <tr>
              <td width="150"><div align="right" class="titles">Picture 
                : </div></td>
              <td width="350" align="left">
                <div align="left">
                  <input size="25" name="file" type="file" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt" class="box"/>
                  
                  </div></td>
                  
            </tr>
            <tr><Td></Td>
            <Td valign="top" height="35px" class="help">Image maximum size <b>400 </b>kb</span>
              <input name="hiddenField" type="hidden" id="hiddenField" value="<?php echo $row_Recordset1['username']; ?>" /></Td>
            </tr>
            <tr><Td></Td><Td valign="top" height="35px"><input type="submit" id="mybut" value="       Upload        " name="Submit"/></Td></tr>
            <tr>
              <td width="200">&nbsp;</td>
              <td width="200"><table width="200" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="200" align="center"><div align="left"></div></td>
                    <td width="100">&nbsp;</td>
                  </tr>
              </table></td>
            </tr>
          </table>
                    </form>
     
      
                  
                  
                  </div>
                  
                  
                  
                  
                  </td>
                
                </tr>
              </tbody>
         </table>
          

          
        
    </div>
           
      </div>
      

        
    </body></html>
    <?php
    mysql_free_result
    ($Recordset1);
    ?>
    thanks for every one help and support

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,495
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I know you said the filename was not getting into the database ...
    but are the actual photos getting put into the "images" directories?

    Trying to determine if at least 1/2 of it is working.

  • #7
    New Coder
    Join Date
    Feb 2010
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post

    Question update / exsplanation

    ok
    the problem i have is i have a upload script that resize the photo but does not submit the photos infomation like the name and the user that uploaded it into the dater base.

    is there a script of there that will upload the image and resize it and submit info like the name of the image to a dater base?

    thanks

    p.s.
    the script before will upload the images and resize it but it will not submit the info into the daterbase i tryed to alter it to submit dater to the dater base but it uploaded and resize but submitted nothing to the dater base

    thanks for all you help every one

  • #8
    New Coder
    Join Date
    Feb 2010
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post

    arrrrrrrrrrrrrrrrrrrr

    ok doing this profile picture thing is getting on my nerves

    is there any tutorial on making a profile picture page or any any scripts

    thanks alot

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,495
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    OK,
    I'm just trying to get it down to one problem.

    Everything works, except putting the data in your MySQL database ... is that correct?

    So that means we do not need to deal with the issue of resizing?

  • #10
    New Coder
    Join Date
    Feb 2010
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post

    Question yes

    100% correct

    i have this code here


    PHP Code:

    <?php require_once('../Connections/mywigan.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }
    }

    $colname_Recordset1 "-1";
    if (isset(
    $_SESSION['MM_Username'])) {
      
    $colname_Recordset1 $_SESSION['MM_Username'];
    }
    mysql_select_db($database_mywigan$mywigan);
    $query_Recordset1 sprintf("SELECT * FROM `user` WHERE username = %s"GetSQLValueString($colname_Recordset1"text"));
    $Recordset1 mysql_query($query_Recordset1$mywigan) or die(mysql_error());
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 mysql_num_rows($Recordset1);
     
     
     



                
                
    error_reporting(0);

    $change="";
    $abc="";


     
    define ("MAX_SIZE","4000");
     function 
    getExtension($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }

     
    $errors=0;
      
     if(
    $_SERVER["REQUEST_METHOD"] == "POST")
     {
         
    $image =$_FILES["file"]["name"];
        
    $uploadedfile $_FILES['file']['tmp_name'];
         
     
         if (
    $image
         {
         
             
    $filename stripslashes($_FILES['file']['name']);
         
              
    $extension getExtension($filename);
             
    $extension strtolower($extension);
            
            
     if ((
    $extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
             {
            
                 
    $change='<div class="msgdiv">Unknown Image extension </div> ';
                 
    $errors=1;
             }
             else
             {

     
    $size=filesize($_FILES['file']['tmp_name']);


    if (
    $size MAX_SIZE*1024)
    {
        
    $change='<div class="msgdiv">You have exceeded the size limit!</div> ';
        
    $errors=1;
    }


    if(
    $extension=="jpg" || $extension=="jpeg" )
    {
    $uploadedfile $_FILES['file']['tmp_name'];
    $src imagecreatefromjpeg($uploadedfile);

    }
    else if(
    $extension=="png")
    {
    $uploadedfile $_FILES['file']['tmp_name'];
    $src imagecreatefrompng($uploadedfile);

    }
    else 
    {
    $src imagecreatefromgif($uploadedfile);
    }

    echo 
    $scr;

    list(
    $width,$height)=getimagesize($uploadedfile);


    $newwidth=60;
    $newheight=($height/$width)*$newwidth;
    $tmp=imagecreatetruecolor($newwidth,$newheight);


    $newwidth1=25;
    $newheight1=($height/$width)*$newwidth1;
    $tmp1=imagecreatetruecolor($newwidth1,$newheight1);

    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

    imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);


    $filename "../images/"$_FILES['file']['name'];

    $filename1 "../images/thumbs/"$_FILES['file']['name'];





    imagejpeg($tmp,$filename,100);

    imagejpeg($tmp1,$filename1,100);

    imagedestroy($src);
    imagedestroy($tmp);
    imagedestroy($tmp1);
    }}

    }

    //If no errors registred, print the success message
     
    if(isset($_POST['Submit']) && !$errors
     {

     
    $con mysql_connect("localhost","root","differ");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
          
           
        





       
    // mysql_query("update {$prefix}users set img='$big',img_small='$small' where user_id='$user'");
         
    $change=' <div class="msgdiv">Image Uploaded Successfully!</div>';
     }
     
     
    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
        <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <meta content="en-us" http-equiv="Content-Language">

        <title>picture demo</title>
        
       <link href=".css" media="screen, projection" rel="stylesheet" type="text/css">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery_002.js"></script>
    <script type="text/javascript" src="js/displaymsg.js"></script>
    <script type="text/javascript" src="js/ajaxdelete.js"></script>
        
         
      <style type="text/css">
      .help
    {
    font-size:11px; color:#006600;
    }
    body {
         color: #000000;
     background-color:#999999 ;
        background:#999999 url(<?php echo $user_row['img_src']; ?>) fixed repeat top left;
        
        
        font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; 
        
        }
            .msgdiv{
        width:759px;
    padding-top:8px;
    padding-bottom:8px;
    background-color: #fff;
    font-weight:bold;
    font-size:18px;-moz-border-radius: 6px;-webkit-border-radius: 6px;
    }
    #container{width:763px;margin:0 auto;padding:3px 0;text-align:left;position:relative; -moz-border-radius: 6px;-webkit-border-radius: 6px; background-color:#FFFFFF }
    </style>

      </head><body>
         <div align="center" id="err">
    <?php echo $change?>  </div>
       <div id="space"></div>
       
     
      
      
      
      <div id="container" >
        
       <div id="con">
       
          
          
            <table width="502" cellpadding="0" cellspacing="0" id="main">
              <tbody>
                <tr>

                  <td width="500" height="238" valign="top" id="main_right">
                 
                  <div id="posts">
                  &nbsp;&nbsp;&nbsp;&nbsp;<img src="<?php echo $filename?>" />  &nbsp;&nbsp;&nbsp;&nbsp;<img src="<?php echo $filename1?>"  />
                    <form method="post" action="" enctype="multipart/form-data" name="form1">
                    <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
                   <tr><Td style="height:25px">&nbsp;</Td></tr>
            <tr>
              <td width="150"><div align="right" class="titles">Picture 
                : </div></td>
              <td width="350" align="left">
                <div align="left">
                  <input size="25" name="file" type="file" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt" class="box"/>
                  
                  </div></td>
                  
            </tr>
            <tr><Td></Td>
            <Td valign="top" height="35px" class="help">Image maximum size <b>400 </b>kb</span>
              <input name="hiddenField" type="hidden" id="hiddenField" value="<?php echo $row_Recordset1['username']; ?>" /></Td>
            </tr>
            <tr><Td></Td><Td valign="top" height="35px"><input type="submit" id="mybut" value="       Upload        " name="Submit"/></Td></tr>
            <tr>
              <td width="200">&nbsp;</td>
              <td width="200"><table width="200" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="200" align="center"><div align="left"></div></td>
                    <td width="100">&nbsp;</td>
                  </tr>
              </table></td>
            </tr>
          </table>
                    </form>
     
      
                  
                  
                  </div>
                  
                  
                  
                  
                  </td>
                
                </tr>
              </tbody>
         </table>
          

          
        
    </div>
           
      </div>
      

        
    </body></html>
    <?php
    mysql_free_result
    ($Recordset1);

    ?>
    and that resizes and save my image but i also want to modify it so that when they upload the picture it submits to my dater base with where the smaller image is stored so i can then put the image on there profile page.

    now i thought this would work (add in about half way down)
    PHP Code:

    //If no errors registred, print the success message
     
    if(isset($_POST['Submit']) && !$errors
     {

     
    $con mysql_connect("localhost","root","password");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
          
           
        

     
    // Gather all required data
      
         
    $dbLink = new mysqli('localhost''root''PASSWORD''mywigan');
            if(
    mysqli_connect_errno()) {
                die(
    "MySQL connection failed: "mysqli_connect_error());
            }
            
    $data $filename1;
           
            
    $username =  $_POST['hiddenField'];
     
            
    // Create the SQL query
            
    $query "
                INSERT INTO `profile_picture` (
                     `file`, `username`
                )
                VALUES (
                   '{$data}', '{$username}'
                )"
    ;
            






       
    // mysql_query("update {$prefix}users set img='$big',img_small='$small' where user_id='$user'");
         
    $change=' <div class="msgdiv">Image Uploaded Successfully!</div>';
     }
     
     
    ?> 
    but it still resizes my image and saves them to my file but does not submit any thing to my daterbase

    what am i doing wrong


    again thanks for you help
    Last edited by phpcodelearner; 02-27-2010 at 08:30 PM.

  • #11
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    The only INSERT/UPDATE line I could see from a brief glance at the code is commented out.

    Code:
    // mysql_query("update {$prefix}users set img='$big',img_small='$small' where user_id='$user'");
    Unless I missed a line elsewhere in your code, that's not going to do much as it is.

  • #12
    New Coder
    Join Date
    Feb 2010
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post

    Question

    no
    PHP Code:
    <?php
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }
    }

    $colname_Recordset1 "-1";
    if (isset(
    $_SESSION['MM_Username'])) {
      
    $colname_Recordset1 $_SESSION['MM_Username'];
    }
    mysql_select_db($database_mywigan$mywigan);
    $query_Recordset1 sprintf("SELECT * FROM `user` WHERE username = %s"GetSQLValueString($colname_Recordset1"text"));
    $Recordset1 mysql_query($query_Recordset1$mywigan) or die(mysql_error());
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 mysql_num_rows($Recordset1);
     
     
     



                
                
    error_reporting(0);

    $change="";
    $abc="";


     
    define ("MAX_SIZE","4000");
     function 
    getExtension($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }

     
    $errors=0;
      
     if(
    $_SERVER["REQUEST_METHOD"] == "POST")
     {
         
    $image =$_FILES["file"]["name"];
        
    $uploadedfile $_FILES['file']['tmp_name'];
         
     
         if (
    $image
         {
         
             
    $filename stripslashes($_FILES['file']['name']);
         
              
    $extension getExtension($filename);
             
    $extension strtolower($extension);
            
            
     if ((
    $extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
             {
            
                 
    $change='<div class="msgdiv">Unknown Image extension </div> ';
                 
    $errors=1;
             }
             else
             {

     
    $size=filesize($_FILES['file']['tmp_name']);


    if (
    $size MAX_SIZE*1024)
    {
        
    $change='<div class="msgdiv">You have exceeded the size limit!</div> ';
        
    $errors=1;
    }


    if(
    $extension=="jpg" || $extension=="jpeg" )
    {
    $uploadedfile $_FILES['file']['tmp_name'];
    $src imagecreatefromjpeg($uploadedfile);

    }
    else if(
    $extension=="png")
    {
    $uploadedfile $_FILES['file']['tmp_name'];
    $src imagecreatefrompng($uploadedfile);

    }
    else 
    {
    $src imagecreatefromgif($uploadedfile);
    }

    echo 
    $scr;

    list(
    $width,$height)=getimagesize($uploadedfile);


    $newwidth=60;
    $newheight=($height/$width)*$newwidth;
    $tmp=imagecreatetruecolor($newwidth,$newheight);


    $newwidth1=25;
    $newheight1=($height/$width)*$newwidth1;
    $tmp1=imagecreatetruecolor($newwidth1,$newheight1);

    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

    imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);


    $filename "../images/"$_FILES['file']['name'];

    $filename1 "../images/thumbs/"$_FILES['file']['name'];





    imagejpeg($tmp,$filename,100);

    imagejpeg($tmp1,$filename1,100);

    imagedestroy($src);
    imagedestroy($tmp);
    imagedestroy($tmp1);
    }}

    }

    //If no errors registred, print the success message
     
    if(isset($_POST['Submit']) && !$errors
     {

     
    $con mysql_connect("localhost","root","differ");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
          
           
        

     
    // Gather all required data
      
    $dbLink = new mysqli('localhost''root''password''mywigan');
            if(
    mysqli_connect_errno()) {
                die(
    "MySQL connection failed: "mysqli_connect_error());
            }
            
    $data $filename;
           
            
    $username =  $_POST['hiddenField'];
     
            
    // Create the SQL query
            
    $query "
                INSERT INTO `profile_picture` (
                     `file`, `username`
                )
                VALUES (
                  '{$data}', '{$username}'
                )"
    ;
        






         


       
    // mysql_query("update {$prefix}users set img='$big',img_small='$small' where user_id='$user'");
         
    $change=' <div class="msgdiv">Image Uploaded Successfully!</div>';
     }
     
     
    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
        <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <meta content="en-us" http-equiv="Content-Language">

        <title>picture demo</title>
        
       <link href=".css" media="screen, projection" rel="stylesheet" type="text/css">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery_002.js"></script>
    <script type="text/javascript" src="js/displaymsg.js"></script>
    <script type="text/javascript" src="js/ajaxdelete.js"></script>
        
         
      <style type="text/css">
      .help
    {
    font-size:11px; color:#006600;
    }
    body {
         color: #000000;
     background-color:#999999 ;
        background:#999999 url(<?php echo $user_row['img_src']; ?>) fixed repeat top left;
        
        
        font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; 
        
        }
            .msgdiv{
        width:759px;
    padding-top:8px;
    padding-bottom:8px;
    background-color: #fff;
    font-weight:bold;
    font-size:18px;-moz-border-radius: 6px;-webkit-border-radius: 6px;
    }
    #container{width:763px;margin:0 auto;padding:3px 0;text-align:left;position:relative; -moz-border-radius: 6px;-webkit-border-radius: 6px; background-color:#FFFFFF }
    </style>

      </head><body>
         <div align="center" id="err">
    <?php echo $change?>  </div>
       <div id="space"></div>
       
     
      
      
      
      <div id="container" >
        
       <div id="con">
       
          
          
            <table width="502" cellpadding="0" cellspacing="0" id="main">
              <tbody>
                <tr>

                  <td width="500" height="238" valign="top" id="main_right">
                 
                  <div id="posts">
                  &nbsp;&nbsp;&nbsp;&nbsp;<img src="<?php echo $filename?>" />  &nbsp;&nbsp;&nbsp;&nbsp;<img src="<?php echo $filename1?>"  />
                    <form method="post" action="" enctype="multipart/form-data" name="form1">
                    <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
                   <tr><Td style="height:25px">&nbsp;</Td></tr>
            <tr>
              <td width="150"><div align="right" class="titles">Picture 
                : </div></td>
              <td width="350" align="left">
                <div align="left">
                  <input size="25" name="file" type="file" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt" class="box"/>
                  
                  </div></td>
                  
            </tr>
            <tr><Td></Td>
            <Td valign="top" height="35px" class="help">Image maximum size <b>400 </b>kb</span>
              <input name="hiddenField" type="hidden" id="hiddenField" value="<?php echo $row_Recordset1['username']; ?>" /></Td>
            </tr>
            <tr><Td></Td><Td valign="top" height="35px"><input type="submit" id="mybut" value="       Upload        " name="Submit"/></Td></tr>
            <tr>
              <td width="200">&nbsp;</td>
              <td width="200"><table width="200" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="200" align="center"><div align="left"></div></td>
                    <td width="100">&nbsp;</td>
                  </tr>
              </table></td>
            </tr>
          </table>
                    </form>
     
      
                  
                  
                  </div>
                  
                  
                  
                  
                  </td>
                
                </tr>
              </tbody>
         </table>
          

          
        
    </div>
           
      </div>
      

        
    </body></html>
    <?php
    mysql_free_result
    ($Recordset1);

    ?>


    that is my complete code where it says this
    PHP Code:

    $dbLink 
    = new mysqli('localhost''root''password''mywigan');
            if(
    mysqli_connect_errno()) {
                die(
    "MySQL connection failed: "mysqli_connect_error());
            }
            
    $data $filename;
           
            
    $username =  $_POST['hiddenField'];
     
            
    // Create the SQL query
            
    $query "
                INSERT INTO `profile_picture` (
                     `file`, `username`
                )
                VALUES (
                  '{$data}', '{$username}'
                )"

    what i thought was going to add to the dater base but did not work.

    Last edited by phpcodelearner; 02-27-2010 at 09:20 PM.

  • #13
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    If you're referring to this piece of code:

    Code:
        $dbLink = new mysqli('localhost', 'root', 'password', 'mywigan');
            if(mysqli_connect_errno()) {
                die("MySQL connection failed: ". mysqli_connect_error());
            }
            $data = $filename;
           
            $username =  $_POST['hiddenField'];
     
            // Create the SQL query
            $query = "
                INSERT INTO `profile_picture` (
                     `file`, `username`
                )
                VALUES (
                  '{$data}', '{$username}'
                )";
    that just creates the query text. You need another line under that to actually do the query.

    Code:
    mysql_query($query) or exit(mysql_error());

  • Users who have thanked MattF for this post:

    phpcodelearner (02-27-2010)

  • #14
    New Coder
    Join Date
    Feb 2010
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post

    Smile pooooooooooooo

    thanks

    how stupid of me i got that angry with this not working i did not check the obvious

    thanks everyone problem sloved again.


    how do i i mark this as solved!!!!!!!!!!!!
    Last edited by phpcodelearner; 02-27-2010 at 09:57 PM.

  • #15
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,495
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Don't worry about getting angry ... we all do that.
    And I knew your frustration wasn't directed at us ... so we're with you man.

    Glad it got resolved.


  •  

    Posting Permissions

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