Jump to content


Photo

Problems with glob()


  • Please log in to reply
2 replies to this topic

#1 akimm

akimm
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 September 2006 - 11:01 PM

I'm using glob to bring about all the smileys in my one directory into a select menu.  It does this fine, I select my smile i chose to use, then submit the form, during the writing however, instead of chosing the name of the smile hypothetically smile1.gif, it numerically lables the smiles like an array.  My problem is I need to use the exact name for the smile and I need to also attach <img src="$_POST[''smile]"> into my php file that does the writing process.  I will post my code thus far, anyone who can help is greatly appreciated.


<form action="journalbox.php" method="POST"><p><b>Date</b><input type="text" value="<b><?php echo date('F j, Y, g:i a');?

></b>" name="date" size="30"></p><p><b>Mood</b>

<select name="mood"><option value="apathetic">apathetic<option value="overjoyed">overjoyed<option

value="inquisitive">inquisitive<option value="outlandish">outlandish<option value="appreciative">appreciative<option

value="confused">confused<option value="displeased">displeased<option value="disgruntled">disgruntled<option

value="sick">sick<option value="terrified">terrified<option value="mental">mental<option value="eruditic">eruditic<option

value="forlorn">forlorn<option value="convuluted">convuluted<option value="ingenious">ingenious<option

value="arrogant">arrogant<option value="free">free<option value="stupid">stupid<option value="moronic">moronic<option

value="pointless">pointless</select><br /><br />
<select name="smile">

This is the form
<?php 

$files = glob("smile/*.gif"); 
##Display $files  
foreach ($files as $key => $value) 
{ 
    echo '<option value="' . $key . '">' . $value . '</option>'; 
} 
?>
</select> 
<p><b>entry</b><TEXTAREA NAME="entry" COLS="80" ROWS="5" WRAP="virtual"></TEXTAREA></P><p><input type="submit" name="submit" 

value="send your entry!"></p></form>

this is the file that writes to my directory
<?php
$filename = "journalaug_sept.txt";
$handle = fopen($filename, 'a');
$write_string = $_POST['date'] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= $_POST['mood'] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= $_POST['smile'] . "<br>";
$write_string .= $_POST['entry'] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= "<HR NOSHADE SIZE=4 COLOR=BLUE>";

fwrite($handle, $write_string);
	fclose($handle);
?>
<h1>Sucessfully posted</h1> 

<br><br>
<?php
echo $_POST['date'] . "<br>";
echo $_POST['mood'] . "<br>";
echo $_POST['smile'] . $_POST['value'] . "<br>";
echo $_POST['entry'] . "<br>";
?>

<br><br>
<a href="http://www.akimm.com/journal06/journal.php">Go To Journal Sean!</a>


#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 08 September 2006 - 08:25 AM

You are passing the array key that holds the filename, not the actual filename. It doesn't actually look like you need the key, so try this:
<?php
foreach(glob("smile/*.gif") as $f) echo "<option value='$f'>$f</option>";
?>


#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 08 September 2006 - 09:02 AM

foreach(glob(realpath('smile') . '/*.gif') as $file) 
{
    echo '<option value="' . hmtlentities($file) . '">' . htmlentities($file) . '</option>';
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users