Jump to content

[SOLVED] PHP to Generate XML from Directory Contents


erikjauli

Recommended Posts

Hi... I'm extremely new to php and am having some trouble getting a php script to function.  I've built a basic flash slideshow using actionscript and xml.  I'm now trying to figure out how to use php to dynamically re-create this xml by reading the contents of a directory.  I was able to find a php script that is supposed to do this here:

 

http://fromvega.com/wordpress/2007/05/13/xml-generator-dir/

 

I'm having a hard time getting the script to run, and I'm not sure what I'm doing wrong.  I am using MAMP to manage/test my site locally.  I go to:

 

http://localhost/test/xmlgen.phps

 

and i get this message :

 

Not Found

The requested URL /test/xmlgen.phps was not found on this server.

Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2 Server at localhost Port 80

 

 

If I change the filename to xmlgen.php and then go to :

 

http://localhost/test/xmlgen.php

 

... i just see the code as plain text.

 

 

The only aspects of the code ive changed are these 3 variables:

 

// list of directories to be read with no trailing slash

$directoryList = array('test/fotos');

 

// name of the XML file

$xmlFileName = 'library.xml';

 

// name of the XML model

$xmlModelName = 'model.xml';

 

 

Anyone have any idea what I'm missing here?  Any help would be appreciated, thanks.

 

-Erik

 

 

 

 

Link to comment
Share on other sites

Here make a page like this:

<?php
echo 'hello I am working.';
?>

save it as index.php, then call this file from localhost.

If you only see "hello I am working." then php is parsing the file, but if you see everything then your server is not setup correctly.

As for the other file relabel it .php instead of .phps  ..... Post back.

Link to comment
Share on other sites

thanks for your help / patience.  Just to make sure I did everything correctly I'll explain exactly how I did this simple test.  I opened dreamweaver, created a new PHP document and pasted the code you provided into the document.  Here's what the code inspector in dreamweaver says:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>

</head>

 

<body>

<?php<br />

echo 'hello I am working.';<br />

?>

</body>

</html>

 

 

I save this file as index.php and call it from the localhost. 

 

If I ran that test correctly... then it seems like my server is not setup correctly.  If that's the case, is that something i need to do within MAMP?

 

-Erik

Link to comment
Share on other sites

You can't insert the code into dreamweaver in the design veiw, you need to get into the nuts and bolts and use code veiw. This is wrong it is html entities:

  <?php<br />
echo 'hello I am working.';<br />
?>

Insert straight into code veiw this.

<?php
echo 'hello I am working.';
?>
Link to comment
Share on other sites

yes... yeah i know I'm getting a little ahead of myself, but I'm slowly learning.  For the other file I now recreated a proper php file using code view.  Almost have it working.  Now when I call that file from localhost I get this message:

 

-------------------------------------------

 

  fromvega XML Generator 2 - fromvega.com

 

---------------------------------------------

Creating XML file for 'test/fotos'...

Couldn't open the directory 'test/fotos'.

Done!

 

 

I'm assuming i need to experiment with this variable of the code until I get it working properly:

 

// list of directories to be read with no trailing slash

$directoryList = array('test/fotos');

 

 

Thanks again for your help, I really appreciate it.

 

-Erik

 

Link to comment
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.