Hi

Sorry, new to this. I understand when using a form to upload image files and information into a mysql database it is best practice to store the image in a directory and the image path in the mysql table. The following code stores the image into a directory and the image name the table using the basename function:-

<?PHP
$target = "images/"; 
  = $target . basename( $_FILES['image']['name']); 

$name=$_POST['name']; 
$pic=($_FILES['image']['name']); 

mysql_connect("localhost", "NAME", "PWORD") or die(mysql_error()) ; 
mysql_select_db("TABLENAME") or die(mysql_error()) ; 

mysql_query("INSERT INTO 'TABLENAME' VALUES ('name' 'image'");
if(move_uploaded_file($_FILES['image']['tmp_name'], $target)) 
?
>

string basename  ( string $path  [, string $suffix  ] )
?>

To store the path e.g images/image.jpeg iin the databse do I use the pathinfo() function instead of the basename function?

thanks mark

OK- No comments there:(

This is part of a site where Flash will be reading an XML file generated from the mysql datasbase- reading image paths.

Perhaps another route I could go down is to have the PHP that dyanmically generates the xml file to concatenate the path e.g by added "images/"

foreach($recordset as $record)
{
$child->new_child("image",$record); }

Anybody have any idea of the syntax to fit this in though?

Hello again - of anybodys reading this :(

The reason for this is to output an XML file for Flash to use. Unfortunately for me this requires an E4X document where one field from a mysql table is an element and the other fields are output as attributes. Is this possible?

eg.

'title', 'description' and 'image' fields in a table become
<?xml version="1.0" encoding="utf-8"?>
<database>
<image path="images/image0.jpg"
title="Name of clothing"
description="This is the description."

<database>

...rather than output the fields as different elements.

The following snippet does not work and i am confused

//select image field
 $image = "SELECT IMAGE FROM TABLE_NAME where  active='1'";

 // create a new XML document
$doc = new DomDocument('1.0');

// create root node
$root = $doc->createElement('$images');
$root = $doc->appendChild($root);

$images->appendChild($dom->createElement('$image'))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.