Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   Dev Hardware ForumsSOFTWAREProgramming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Hardware Forums Sponsor:
  Trader Rating: 0 · #1  
Old February 7th, 2007, 05:12 AM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 294 Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 23 h 37 m 7 sec
Reputation Power: 5
PHP Image Database

After many hours, I have finally come up with the following code, that saves a file onto the server, in a folder called "Upload"....

...Does anybody know how to store the image path into a database called Photos and table called "Images" containing a column call "Path"?

The following is the code currently being used.

PHP Code:
<?php
if (($_FILES["file"]["type"] == "image/gif")
|| (
$_FILES["file"]["type"] == "image/jpeg")
&& (
$_FILES["file"]["size"] < 20000))
  {
  if (
$_FILES["file"]["error"] > 0)
    {
    echo 
"Return Code: " $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo 
"Upload: " $_FILES["file"]["name"] . "<br />";
    echo 
"Type: " $_FILES["file"]["type"] . "<br />";
    echo 
"Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo 
"Temp file: " $_FILES["file"]["tmp_name"] . "<br />";

    if (
file_exists("upload/" $_FILES["file"]["name"]))
      {
      echo 
$_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      
move_uploaded_file($_FILES["file"]["tmp_name"],
      
"upload/" $_FILES["file"]["name"]);
      echo 
"Stored in: " "upload/" $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo 
"Invalid file";
  }
?>


Many Thanks,


Moderator's Note: PHP tags added by Nilpo

Last edited by Nilpo : February 7th, 2007 at 12:06 PM.

Reply With Quote
  Trader Rating: 0 · #2  
Old February 7th, 2007, 10:49 AM
Sand Man's Avatar
Sand Man Sand Man is offline
¯\(º_o)/¯
Dev Hardware Loyal (3000 - 3499 posts)
 
Join Date: Jun 2005
Location: in a daydream
Posts: 3,433 Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)  Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 9 h 32 m 46 sec
Reputation Power: 4692
Send a message via MSN to Sand Man Send a message via Google Talk to Sand Man
are you planning on storing the files in other folders than the upload folder? will you have a hierarchy like

uploads/user1
uploads/user2
....

If no, then when you display the image, you can just include the path in you image tag:
Code:
<img src="uploads/<?php echo $imagename ?>">

if yes, then you will need to come up with a way in which you will store the images in subfolders and include that subfolder in the path column.

if you give all your images unique names, then you may not have a need to store them in subfolders. when i'm making unique names, i usually have a combination of year+month+date+hour+minute+second+userid+sessioni d
__________________
How much net work could a network work, if a network could net work?

Last edited by Sand Man : February 7th, 2007 at 10:54 AM.

Reply With Quote
  Trader Rating: 0 · #3  
Old February 12th, 2007, 03:14 AM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 294 Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 23 h 37 m 7 sec
Reputation Power: 5
PHP Image Database

SandMan,

How do I put the following code inside a loop, so that it displays all the images/paths, within the database?

<img src="uploads/<?php echo $imagename ?>">

What is "$imagename", where would it be in the following code?

Code:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("photos", $con);

if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
&& ($_FILES["file"]["size"] < 90000))
{
  if ($_FILES["file"]["error"] > 0)
  {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  }
  else
  {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
    {
      echo $_FILES["file"]["name"] . " already exists. ";
    }
    else
    {
      $file = ("upload/" . $_FILES["file"]["name"]);
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      
      mysql_query("INSERT INTO images (path)
      VALUES('$file')");    
    }
  }
}
else
{
  echo "Invalid file";
}
?>
Many Thanks,

Reply With Quote
  Trader Rating: 0 · #4  
Old February 12th, 2007, 06:13 AM
Sand Man's Avatar
Sand Man Sand Man is offline
¯\(º_o)/¯
Dev Hardware Loyal (3000 - 3499 posts)
 
Join Date: Jun 2005
Location: in a daydream
Posts: 3,433 Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)Sand Man User rank is General 56th Grade (Above 100000 Reputation Level)  Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141591 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 9 h 32 m 46 sec
Reputation Power: 4692
Send a message via MSN to Sand Man Send a message via Google Talk to Sand Man
you'll need to loop through your record set like this: http://resources.bravenet.com/artic..._mysql_basics/3

Reply With Quote
  Trader Rating: 0 · #5  
Old February 12th, 2007, 06:44 AM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 294 Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 23 h 37 m 7 sec
Reputation Power: 5
PHP Image Database

SandMan,

What is stored in the $imagename variable?, i currently have a database called photos, and a table called images containing one field/column called path.

How do i pass the information in the path field/column to the image on the page, to display the appropriate image. The following is what i have so far in terms of coding, to the first image.

The data stored inside the database, is in the following format.

Example: upload/45_j11.jpg

Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("photos", $con);

$imagename= mysql_query("SELECT * FROM images
WHERE path");

while($row = mysql_fetch_array($result))
{
}
?>

</head>

<body>
<img src="$imagename">
</body>
</html>
Many Thanks,

Last edited by Salchester : February 12th, 2007 at 07:26 AM.

Reply With Quote
Reply

Viewing: Dev Hardware ForumsSOFTWAREProgramming > PHP Image Database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway