Is there a way to iterate thru each image in a directory
Moderator: General Moderators
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
Is there a way to iterate thru each image in a directory
I have been trying to solve this problem multiple ways, and this is just a thought I had just now, can I print each smile graphic in my directory /smile/ onto a php form?
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
I didn't know
Whether it was or not. This is a previously asked question, just a different approach to my problem.
I have 92 .gif smiles. I'd like to print all of them and then be able to select the one i'd like to use on any one journal entry. I tried doing a foreach array, which hadn't worked. I know you're rather experienced any way I can go about this problem? Thanks.
I have 92 .gif smiles. I'd like to print all of them and then be able to select the one i'd like to use on any one journal entry. I tried doing a foreach array, which hadn't worked. I know you're rather experienced any way I can go about this problem? Thanks.
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
Here they are, 2 thta I found within the forum
first attempt
Second attempt
Code: Select all
<?php
$smiles = array (
option value="smile1" => ['<img src='smile1.gif'],
//et cetera?
);?>Code: Select all
##Piece of code from form
<select name="smile">
<?php
$smile = array('2guns', 'somethingElse');
/**
* This generates a drop down with
* the array index as the key and
* the smilie name as the value in the form
**/
foreach ($smile as $key => $value)
{
echo '<option value="' . $key . '">' . $value . '</option>';
}
?>
</select>
## Code that writes to the file
<?php
$smile = array('2guns', 'somethingElse');
$img_id = $_POST['smile'];
echo '<img src="/journal06/smile/' . $smile[$img_id] . '.gif" />';
$filename = "journalaug_sept.txt";
$handle = fopen($filename, 'a');
$write_string = $_POST['date'] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= $_POST['mood'] . $_POST['smile'] . $smile[$img_id] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= $_POST['entry'] . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= "<HR NOSHADE SIZE=4 COLOR=BLUE>";
fwrite($handle, $write_string);
fclose($handle);
?>- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
Feyd or someone
Code: Select all
<?php
$files = glob("http://www.akimm.com/journal06/smile/*.gif");
##Display $files
<select name="smile">
foreach ($files as $key => $value)
{
echo '<option value="' . $key . '">' . $value . '</option>';
}
?>
</select>Is this the basic idea I'm searching for?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: so just
Not likely, unless you have the webroot as the server root which would be plain stupidakimm wrote:/journal06/smile/
How about "./journal06/smile/" ?
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
It worked on the form..
it displays textual forms of all the contents.. but i doesn't translate them into the textfile and then into the visible journal.
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
thus far I have this.
here is the form thus far
Here is the file that processes the form.
Code: Select all
<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">
<?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>Here is the file that processes the form.
Code: Select all
<?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 .= "<img src=$_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>You are setting the value of the select box to the array key. Try setting it to the file name 
To:
Code: Select all
foreach ($files as $key => $value)
{
echo '<option value="' . $key . '">' . $value . '</option>';
}Code: Select all
foreach ($files as $key => $value)
{
echo '<option value="' . $value. '">' . $value . '</option>';
}