Jump to content

Writing file names to a file...


pneudralics

Recommended Posts

I'm trying to write all jpg names that is named with a number to an xml file. Whenever I echo it and look at the source I can see that they are displaying. When I check the test.xml file it only shows one value. How can I make it write more than one value to the xml file?

 

//Set directory
$search_dir = '.';
$dp = opendir ($search_dir);

//List directories
while ($item = readdir ($dp) ) {
if ( (is_dir ($item)) AND (substr($item, 0, 1) != '.') ) {
	echo "$item<br />\n";
}
}

rewinddir ($dp); //Reset pointer


//List files
while ($item = readdir ($dp) ) {
if ( (is_file ($item)) AND (substr($item, 0, 1) != '.') ) {
//Get file size
$fs = filesize ($item);

//Get file modification date
$lm = date ('F j, Y' , filemtime($item));

	//Find image
	$imagepattern = '/^([0-9]){1,}.jpg$/';
	$imagesubject = "$item";

	if (preg_match($imagepattern, $imagesubject, $imagematches)) {
		//Open file
		$imagesubject2 = "<image Thumb=\"tn_$imagesubject\" Large=\"$imagesubject\"/>";
		if ($fp = fopen ('test.xml', 'w')) {
		fwrite ($fp, "$imagesubject2");
		fclose ($fp);
		echo "$imagesubject2";
		}
	}
}
}

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.