[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP Full Image Gallery

Posted on 2006-04-11
7
Medium Priority
?
400 Views
Last Modified: 2010-04-17
Hi,

Could anybody please tell me how I could create a simple PHP Image gallery with thumbs.
I would like to upload images to a directory on the server and the keywords to mysql. So when I search
through the mysql table, I have a link to the image

Thanks
0
Comment
Question by:babyboy808
  • 3
  • 3
7 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16431918
Do you have a more specific problem ?


i) Upload file:
http://www.phpfreaks.com/tutorials/36/0.php

ii) Add info to database
http://uk2.php.net/mysql

iii) Query database
<see ii>

iv) Output image path to HTML, based on results of iii
...I don't wanna teach you to suck eggs (unless you don't know how?)...
0
 

Author Comment

by:babyboy808
ID: 16431986
Hi i am a complete newb, I couldn't get that code to work?

0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16432049
Can you program in PHP at all?

If not, then you need to learn that first:

http://www.w3schools.com/php/default.asp


[ Perhaps you should stick with photobucket.com for now ;p ]
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:babyboy808
ID: 16432158
Ok, appoligies for the broad question. Here is my php code:

<?php
$file = $_FILES['file'];
$fp = fopen($file['tmp_name'], "r");
$data = fread($fp, filesize($file['tmp_name']));
fclose($fp);

$save = fopen("Docs/".$file['name'], "w");
fwrite($save, $data);
fclose($save);

$keywords = $_REQUEST['keywords'];
echo("Keywords: ".$keywords."<BR>\nFiletype: ".$file['type']."<BR>\n<IMG height=\"40\" width=\"40\" src=\"Docs/".$file['name']."\"><A href=\"Docs/".$file['name']."\">Click here to open the file</A>");

?>

I can get the above to work now, All i need to know is how would i insert keywords from the form to the db in the same submit.

0
 

Author Comment

by:babyboy808
ID: 16432168
400 points up
0
 
LVL 17

Expert Comment

by:Dushan De Silva
ID: 16433144
http://www.comdevweb.com/photogallery.php

Excellent.

Free download to try it and then you can buy a license, affordable.

You can have idea from following solution.

http://www.experts-exchange.com/Web/Q_21806605.htm


BR Dushan
0
 
LVL 25

Accepted Solution

by:
InteractiveMind earned 1600 total points
ID: 16434933
Sorry for the delay; I don't seem to be recieving any email notif's from this site...  :(

> All i need to know is how would i insert keywords from the form to the db in the same submit
Well, below is some of a class that I created a couple of months back for my site, which basically makes life a bit easier, to connect to a MySQL db, and perform queries and updates, etc.


<?php
      
      class MySQL
      {
            
            var $svr      = "abc.domain.com" ;
            var $user     = "admin" ;
            var $password = "password123" ;
            var $database = "dbName" ;
            
            var $link ;
            var $result ;
            
            var $temp ;
            var $found = false ;
            
            
            function __construct()
            {}
            
            function __destruct()
            {
                  $this->_close() ;
            }
            
            
            function _query( $sql, $ret )
            {
                  if ( $ret )
                  {
                        return @mysql_query( $sql ) ;
                  } else
                  {
                        $this->result = @mysql_query( $sql ) ;
                  }
            }
            
            function _load()
            {
                  return @mysql_select_db( $this->database, $this->link ) ;
            }
            
            function _connect()
            {
                  if ( $this->password == "" )
                  {
                        $this->link = @mysql_connect( $this->svr, $this->user ) ;
                  } else
                  {
                        $this->link = @mysql_connect( $this->svr, $this->user, $this->password ) ;
                  }
            }
            
            function _next()
            {
                  return @mysql_fetch_assoc( $this->result ) ;
            }
            
            function _clear()
            {
                  @mysql_free_result( $this->result ) ;
            }
            
            function _close()
            {
                  @mysql_close( $this->link ) ;
            }
      }
      
?>



And an example of use:

    include( "TheClassesFileName.php" ) ;
   
    $dtj = new MySQL() ;
    $dtj->_connect() ;
   
    if ( ! $dtj->link )
    {
        die( "An unexpected MySQL error has occurred. [C]<br />I'll try and get it fixed as soon as possible." ) ;
    }
   
    if ( ! $dtj->_load() )
    {
        die( "An unexpected MySQL error has occurred. [L]<br />I'll try and get it fixed as soon as possible." ) ;
    }
   
    // Perform an update
    $dtj->_query( "INSERT INTO .. etc .." ) ;
   
    // Perform a query
    $dtj->_query( "SELECT SQL_CACHE id,title FROM articles ORDER BY id DESC LIMIT 5", false ) ;
   
    // The results from the query can be retrieved one by one, with a call to the _next() function:
    while ( $row = $dtj->_next() )
    {
        $cc .= "<a href=\"/articles/article.php?id={$row['id']}\">" . $row['title'] .  "</a>" ;
    }
   
    // clear the result set and close the SQL connection when done:
    $dtj->_clear() ;
    $dtj->_close() ;


Obviously though, you'd want to run an update something along the lines of:

    $dtj->_query( "INSERT INTO my_table_name SET keywords = '$keywords' WHERE some_condition_is_true" ) ;
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Progress
Starting up a Project

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question