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: 293 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: 6
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 online now
٩( ͡๏̯͡๏)۶
Click here for more information.
 
Join Date: Jun 2005
Location: in a daydream
Posts: 4,003 Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)  Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 1 Month 1 Week 22 h 57 m 17 sec
Reputation Power: 14540
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: 293 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: 6
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 online now
٩( ͡๏̯͡๏)۶
Click here for more information.
 
Join Date: Jun 2005
Location: in a daydream
Posts: 4,003 Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 203rd Grade (Above 100000 Reputation Level)  Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2Folding Points: 888398 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 1 Month 1 Week 22 h 57 m 17 sec
Reputation Power: 14540
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: 293 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: 6
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




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek