Jump to content

[SOLVED] PHP XML Generator including .DS_Store File


erikjauli

Recommended Posts

Hi... I'm very new to PHP and thanks to help on this forum I was able to build a dynamic image rotator using actionscript, xml, and php today.  I have an swf with actionscript that calls a php file to generate an xml of a directories contents.  The swf then creates a random slideshow based on that xml.  The only problem I'm having is that the php script I am using includes ".DS_Store" in the generated XML.  I think that is causing problems with the slideshow because it randomly stops when it should loop continuously.  Im assuming when it tries to grab the .ds store file its causing this problem.  Ive attached the php file, the model XML, and the generated xml.  Any ideas?  Thanks.

 

[attachment deleted by admin]

Link to comment
Share on other sites

i am currently building/managing/hosting the site locally on a mac using mamp.  maybe once i migrate the site to an external host this issue will be resolved.  curious if anyone else has experienced this problem before and how they've resolved it.  thanks

 

-Erik

Link to comment
Share on other sites

the .DS_Store file is a pretty common file on a mac, however it's a "hidden" file.  i was under the impression that it was a necessary file that exists within folders so I was hesitant to manually delete it. From what ive researched its not vital and I should be able to manually delete it through terminal.  I'll give that a try in the morning and see what happens

Link to comment
Share on other sites

Yes, you can delete it, BUT, another one will be created when a Mac opens the folder again.

Anytime you scan a directory for files, you should be excluding hidden files.

Unless you are specifically looking for them anyway.

$D = scandir($P);
foreach($D as $F){
if($F{0} != '.'){
// do stuff here
}
}

 

Link to comment
Share on other sites

Thanks for the suggestion, for some reason that command wasn't working.  I was however able to get it to work by using this:

 

foreach ($dir as $file) {

  if ($dir->isDot()) {continue;} 

    if (strripos($file,".jpg")==true) {

 

 

 

That solved the problem by only including .jpg's in the xml which is exactly what im looking for.  Thanks again.

 

-Erik

 

 

Link to comment
Share on other sites

Some small details:

Are all these files under your control? can a file get in there with .jpeg?

or other formats?

Also, the ==true is redundant

if(stripos($file,'.jpg')==true)

is functionally identical to

if(stripos($file,'.jpg'))

 

that usage of strpos() will work fine, but strpos and stripos can be tricky, watch out for them in the future. (php.net is your friend)

 

...just a few general pointers

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.