Jump to content

Recommended Posts

hello everyone,

 

I need to retrieve images and their information from MySQL database in xml format. I have written the following code:

 

<?php

$link = mysql_connect("localhost","root","");

// Query the database and get all the records from the All table

mysql_select_db("dresses");

$query_rsAll = "SELECT * FROM pictures";

$rsAll = mysql_query($query_rsAll) or die(mysql_error());

$row_rsAll = mysql_fetch_assoc($rsAll);

$totalRows_rsAll = mysql_num_rows($rsAll);

?><?php echo('<?xml version="1.0" encoding="utf-8"?>');?>

<dresses>

<?php if ($totalRows_rsAll > 0) { // Show if recordset not empty ?>

  <?php do { ?>

<pictures>

<?php print('<image>' . ($row_rsAll['image']) . '</image>'); ?>

<br>

<?php print('<ext>' . $row_rsAll['ext'] . '</ext>'); ?>

<br>

<?php print('<category>' . $row_rsAll['category'] . '</category>'); ?>

<br>

<?php print('<price>' . $row_rsAll['price'] . '</price>'); ?>

<br>

<?php print('<buy>' . $row_rsAll['buy'] . '</buy>'); ?>

</pictures>

<?php } while ($row_rsAll = mysql_fetch_assoc($rsAll)); ?>

<?php } // Show if recordset not empty ?>

</dresses>

<?php

mysql_free_result($rsAll);

?>

 

Output: /9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAUAAA/+4ADkFkb2JlAGTAAAAAAf/bAEMAAgICAgICAgICAgMCAgIDBAMCAgMEBQQEBAQEBQYFBQUFBQUGBgc/NFvKzPC1vfXce5Ld8oVdBumQHd5eCKAPxr/AGhf2n/iL8etUjl1CHTtC0zSJVutE0nSrSLzrdlBzKNTaL7cSy8NhlRv7g6UAfOfhi1vr6+N3qV2yWmkxxT2tnHkCaWSQpGi5KkABXbGOwGM0Af1a/DvZJOKAP5vv2qb221X4meKtRuZraK98Q6jJq8WjQXKSm0S/meaO2vE3sqXCLtLIGOW3EY+SgDzLw5pM9tpUUsem208+ptI8iG0AbywTguXJdsrzz8uMYoA244p7eeS4R7W2WQbEawthEzqv3S8qElto4AxkCgDC8Q21nfaZLcXMbiQxxSyQ3MaeYCsnU7l3/xAnJ4oAzYLPXNetntbe6h0LSI38vHlvJd3I7iPIKqOOTmgBbvwpokVsEjErOTgAgnOeaANy5dLASc+vnc0AfTlABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFAH/9k=

png

kurta collection

2000

http://localhost/Picturz.php

 

 

Issue:

The problem is that instead of displaying images in proper format it is showing them in character form. Can anyone help me solve this issue?

 

 

Link to comment
https://forums.phpfreaks.com/topic/235831-php-xml-help/
Share on other sites

So you're storing the images as binary data in your database?

 

For one, XML doesn't support the image tag, as far as I know. You best bet will be to link it to a script (using the image's unique ID in the database) that will send the browser image headers, and dump out the raw binary data of the picture.

 

There are lots of tutorials on how to do this. Here's one

http://www.codewalkers.com/c/a/Database-Articles/Storing-Images-in-Database/3/

 

He doesn't sanitize user input in that example though. I suggest doing it to avoid SQL injection

Link to comment
https://forums.phpfreaks.com/topic/235831-php-xml-help/#findComment-1212260
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.