Jump to content

doddsey_65

Members
  • Posts

    902
  • Joined

  • Last visited

  • Days Won

    9

Posts posted by doddsey_65

  1. i have an image resizing script:

     

    <?php
    class SimpleImage {
       var $image;
       var $image_type;
       function load($filename) {
          $image_info = getimagesize($filename);
          $this->image_type = $image_info[2];
          if( $this->image_type == IMAGETYPE_JPEG ) {
             $this->image = imagecreatefromjpeg($filename);
          } elseif( $this->image_type == IMAGETYPE_GIF ) {
             $this->image = imagecreatefromgif($filename);
          } elseif( $this->image_type == IMAGETYPE_PNG ) {
             $this->image = imagecreatefrompng($filename);
          }
       }
       function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
          if( $image_type == IMAGETYPE_JPEG ) {
             imagejpeg($this->image,$filename,$compression);
          } elseif( $image_type == IMAGETYPE_GIF ) {
             imagegif($this->image,$filename);         
          } elseif( $image_type == IMAGETYPE_PNG ) {
             imagepng($this->image,$filename);
          }   
          if( $permissions != null) {
             chmod($filename,$permissions);
          }
       }
       function output($image_type=IMAGETYPE_JPEG) {
          if( $image_type == IMAGETYPE_JPEG ) {
             imagejpeg($this->image);
          } elseif( $image_type == IMAGETYPE_GIF ) {
             imagegif($this->image);         
          } elseif( $image_type == IMAGETYPE_PNG ) {
             imagepng($this->image);
          }   
       }
       function getWidth() {
          return imagesx($this->image);
       }
       function getHeight() {
          return imagesy($this->image);
       }
       function resizeToHeight($height) {
          $ratio = $height / $this->getHeight();
          $width = $this->getWidth() * $ratio;
          $this->resize($width,$height);
       }
       function resizeToWidth($width) {
          $ratio = $width / $this->getWidth();
          $height = $this->getheight() * $ratio;
          $this->resize($width,$height);
       }
       function scale($scale) {
          $width = $this->getWidth() * $scale/100;
          $height = $this->getheight() * $scale/100; 
          $this->resize($width,$height);
       }
       function resize($width,$height) {
          $new_image = imagecreatetruecolor($width, $height);
          imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
          $this->image = $new_image;   
       }      
    }
    ?>
    <?php
       include('resize.php');
       $image = new SimpleImage();
       $image->load('path/image.png');
       $image->resize(400,300);
       $image->save('path/image.png');
    ?>

     

    Is there any way i can incoroprate this into the upload form?

  2. When a user uploads their image i want to be able to get the dimensions and resize accordingly before the image is uploaded. I want the images to be only 100x100. how would i go about this? I already have an upload function just need these things added to it.

  3. Okay i got the format to work but when i click next page it just shows up the same results not the next ones.

     

    <?php 
    
    ob_start();
    include('header.php'); 
    include('db.php');
        $db=mysql_connect($db_host,$db_user,$db_pass)
    or die ('I cannot connect to the database because: ' . mysql_error());
        mysql_select_db($db_name,$db);
    if (!(isset($pagenum))) 
    { 
    $pagenum = 1; 
    } 
    
    
    $data = mysql_query("SELECT * FROM tutorials") or die(mysql_error()); 
    $rows = mysql_num_rows($data); 
    
    $page_rows = 3; 
    
    $last = ceil($rows/$page_rows); 
    
    if ($pagenum < 1) 
    { 
    $pagenum = 1; 
    } 
    elseif ($pagenum > $last) 
    { 
    $pagenum = $last; 
    } 
    
    $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
    
    echo '<div id="page">';
    echo '<div id="content"><br />';
    echo '<h2 class="title">Tutorials By Hamish Hill</h2><br />';
    
    $sql = "SELECT name, fullname, description, link, path
            FROM   tutorials
            WHERE  username='hamsterhill' $max";
    
    $result = mysql_query($sql);
    while ($row = mysql_fetch_assoc($result)) {
    
    
    echo '<div class="post">';
    echo '<p class="meta">' .$row["fullname"]. ' | ' .$row["name"]. '<img 
    
    src="images/img08.png" alt="bullet"></p>';
    
    echo '<div class="entry">';			
    echo '<p><img src=' .$row['path']. ' hspace=10 align=left>';
    echo $row['description']. '</p>'; 
    echo '</div>';
    echo '</div>';
    
    } 
    
    echo "<p> Page $pagenum of $last </p>";
    
    if ($pagenum == 1) 
    {
    } 
    else 
    {
    echo " <p><a href='{$_SERVER['PHP_SELF']}?pagenum=1' class=links> <<-First</a> ";
    echo " ";
    $previous = $pagenum-1;
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous' class=links> <-Previous</a> 
    
    </p>";
    } 
    
    if ($pagenum == $last) 
    {
    } 
    else {
    $next = $pagenum+1;
    echo " <p><a href='{$_SERVER['PHP_SELF']}?pagenum=$next' class=links>Next -></a> ";
    echo " ";
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last' class=links>Last ->></a></p> ";
    
    }
    echo '</div>';
    
    
    include('footer.php');
    ob_flush(); 
    ?>

  4. Okay here is the page in question: http://blenderteachings.000a.biz/tutorials.hamishhill.php

     

    I have the records in a database(tutorial name, username description etc). I am pulling these and displaying them but i need them to be set out like this http://blenderteachings.000a.biz/index.php

     

    But my code doesnt do it like that. Any ideas?

     

    Heres the code:

     

    <?php 
    
    ob_start();
    include('header.php'); 
    include('db.php');
        $db=mysql_connect($db_host,$db_user,$db_pass)
    or die ('I cannot connect to the database because: ' . mysql_error());
        mysql_select_db($db_name,$db);
    
    if (!(isset($pagenum))) 
    { 
    $pagenum = 1; 
    } 
    
    
    $data = mysql_query("SELECT * FROM tutorials") or die(mysql_error()); 
    $rows = mysql_num_rows($data); 
    
    $page_rows = 3; 
    
    $last = ceil($rows/$page_rows); 
    
    if ($pagenum < 1) 
    { 
    $pagenum = 1; 
    } 
    elseif ($pagenum > $last) 
    { 
    $pagenum = $last; 
    } 
    
    $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
    
    
    $sql = "SELECT username, fullname, description, link
            FROM   tutorials
            WHERE  username='hamsterhill' $max";
    
    $result = mysql_query($sql);
    while ($row = mysql_fetch_assoc($result)) {
    ?>
    
    <div id="page">
    <div id="content"><br>
    <div class="post">
    <p class="meta"><?php echo $row["fullname"] . ' | ' .$row["username"]; ?>
    <img src="images/img08.png" alt="bullet"></p>
    
    	<div class="entry">			
    	<?php echo $row['description']; echo '<br />'; } ?>
    	</div>
    </div>   
    
    <?php
    echo " Page $pagenum of $last <p>";
    
    if ($pagenum == 1) 
    {
    } 
    else 
    {
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
    echo " ";
    $previous = $pagenum-1;
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
    } 
    
    
    //This does the same as above, only checking if we are on the last page, and then 
    
    generating the Next and Last links
    if ($pagenum == $last) 
    {
    } 
    else {
    $next = $pagenum+1;
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
    echo " ";
    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
    } 
    ?>
    </div>
    
    <?php include('footer.php');
    ob_flush(); 
    mysql_close($db);
    ?>

  5. I want to select values from a db table and return them but when i echo the name field it brings a result from a dif table.

     

    include('db.php');
        $db=mysql_connect($db_host,$db_user,$db_pass)
    or die ('I cannot connect to the database because: ' . mysql_error());
        mysql_select_db($db_name,$db);
    
    $query= "SELECT name, description, link, username, fullname FROM 'tutorials' WHERE id=1";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_array($res)
    
    ?
    <p class="meta"><?php echo $row['username']; ?>

  6. ok well i think the easiest thing to do is get rid lol, its not really an important feature as the site isnt a foru or anything like that just a tut site. Cheers anyway, but i think working round this is gonna cause more problems than i need lol.

  7. so if there is no way to delete the record when they are logged out automatically how would i change this code so they arent logged out automatically, and would that even be feasable(spelling?) ie security?

  8. I have a login system setup and i made it echo number of users online by inserting the username into a dif tble when they log in and echoing the numrows in tht table. And when they logout it is removed, however when the session times out and they are logged out automatically it doesnt delete the row so it still says there is a user online. Here is the logout code:

     

    <?php 
    
    
    $username = $_COOKIE['ID_my_site'];
    $db=mysql_connect("myinfo") or die(mysql_error()); 
    mysql_select_db("mydb") or die(mysql_error());
    
    
    $past = time() - 100; 
    setcookie(ID_my_site, gone, $past); 
    setcookie(Key_my_site, gone, $past); 
    $sql="DELETE FROM online WHERE username = '$username'";
    header("Location: index.php"); 
    
    
    
    ?>

  9. Okay here is the code:

     

    if (isset ($_COOKIE['ID_my_site'])) 
    { 
    $username = mysql_real_escape_string($_COOKIE['ID_my_site']); 
    $pass = mysql_real_escape_string($_COOKIE['Key_my_site']);
    $check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or trigger_error (mysql_error()); 
    
    if (mysql_num_rows ($check) > 0)
    {
    	$info = mysql_fetch_array ($check);
    
    	//if the cookie has the wrong password, they are taken to the login page 
    	if ($pass != $info['password'])
    	{ header("Location: login.php"); }
    
    	else
    	{
    
    $uploadDir = 'uploads/';
    
    if(isset($_POST['upload']))
    {
    $fileName = $_FILES['userfile']['name'];
    $tmpName = $_FILES['userfile']['tmp_name'];
    
    $filePath = $uploadDir . $fileName;
    
    $result = move_uploaded_file($tmpName, $filePath);
    if (!$result) {
    echo "Error uploading file";
    exit;
    }
    
    if(!get_magic_quotes_gpc())
    {
    $filePath = addslashes($filePath);
    } 
    
    $query = ("UPDATE users SET path='$filePath' WHERE username='$username'");
    echo $query;
    
    }
    
    
    }
    
    }
    }
    else
    { header("Location: login.php"); exit (0); } 
    
    ob_flush(); 
    ?>
    

     

    When i run it the image is uploaded to the server but the db row isnt updated. Yet when i echo the query and put that into phpmyadmin it works fine. So why doesnt it work in php?

     

    Cheers

  10. <?php
    
    $to_email = "info@ideatoceo.com";
    $subject = "Greetings";
    $message = 
    echo '<table width="676"><tr>Hi    
    <td width="30" height="52"><img src="Side.gif" width="30" height="50" alt="Corner" /></td>    
    <td width="600"><img src="Top.gif" width="600" height="50" alt="Top" /></td>    
    <td width="30"><img src="Side.gif" width="30" height="50" alt="Corner" />
    </td></tr></table>'; ?>

  11. Okay my code doesnt seem to work but i dont know why

     

    $uploadDir = 'uploads/';
    
    if(isset($_POST['upload']))
    {
    $fileName = $_FILES['userfile']['name'];
    $tmpName = $_FILES['userfile']['tmp_name'];
    
    $filePath = $uploadDir . $fileName;
    
    $result = move_uploaded_file($tmpName, $filePath);
    if (!$result) {
    echo "Error uploading file";
    exit;
    }
    
    if(!get_magic_quotes_gpc())
    {
    $filePath = addslashes($filePath);
    } 
    
    $query = ("UPDATE users SET path = '$filepath' WHERE username = '$username'") or die
    
    (mysql_error());

     

    It uploads the image but not the path

    Username is already defined earlier in the code and my form is fine. Can anyone see why its not working?

  12. @emopoops that makes no sense that he would delete a user by the url. you should never delete a user by a name or age or some other value that can be in another users field. There should be a unique value in the database that identifies the user. Hence the use of an incrementing id. Then you can delete it by using its UNIQUE id. Almost every table I make in the database has a unique id.

     

    same here, i have an ai on an id table. cheers for the help people. I did think halfway through however why dont i just gointo the database and delete them, but im going to use this way anyway cos my db loads too slowly. Cheers

  13. I presume you have a unique ID column for the table users right?

     

    yes, but how would i get the hyperlink to know its the user next to it that i want it to delete

     

    Eg. User: Tom [delete]

        User: Dick [delete]

        User: Harry[delete]

     

    How would i delete tom with the code i am using to display them

  14. I currently have a user managment system im working on. What i want is to have a hyperlink next to the rows that are pulled(see code below). with this button i can delete the respective row from the db therefore deleting the user. Here is the code i am using to display their details:

     

    $sql = "SELECT name, email, date FROM users";
    $res = mysql_query($sql, $db);
    while($row = mysql_fetch_array($res, MYSQL_ASSOC))
    
    {
    
    echo $row['name'] . ": " . $row['email'] . " -- " . $row['date'];
    echo "<br />";
    
    }

    I know how to delete records, what i dont know how to do is to delete the record I want ie. the one next to the delete link if you know what i mean.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.