If/Else with form
Posted: Fri Apr 10, 2009 12:42 pm
I have a directory which will have 1 or 0 images in it.
I want to say "IF there is a file in the directory, print it, ELSE print the form."
Here is the code I am struggling with:
<?php
$dir = 'imagefolder';
if (count(glob("$dir/*")) === 1) {
$handle = opendir('imagefolder');
if($handle) {
while(false !== ($file = readdir($handle))) {
if(preg_match("/\w+(.jpg)/",$file)) {
print "<img src='imagefolder/$file'>";
print "$file <br>";
}
}
closedir($handle);
}
else {
?>
<fieldset>
<legend>Image upload</legend>
<p>Select Matchcard from your computer and click 'Upload' </p>
<form name="form" enctype="multipart/form-data" method="post" action="upload.php" />
<p><input type="file" size="32" name="my_field" value="" /></p>
<p class="button"><input type="hidden" name="action" value="image" />
<input type="submit" name="Submit" value="Upload" /></p>
</form>
</fieldset>
<?
;
}
}
?>
Hope someone can help.
Wayne.
I want to say "IF there is a file in the directory, print it, ELSE print the form."
Here is the code I am struggling with:
<?php
$dir = 'imagefolder';
if (count(glob("$dir/*")) === 1) {
$handle = opendir('imagefolder');
if($handle) {
while(false !== ($file = readdir($handle))) {
if(preg_match("/\w+(.jpg)/",$file)) {
print "<img src='imagefolder/$file'>";
print "$file <br>";
}
}
closedir($handle);
}
else {
?>
<fieldset>
<legend>Image upload</legend>
<p>Select Matchcard from your computer and click 'Upload' </p>
<form name="form" enctype="multipart/form-data" method="post" action="upload.php" />
<p><input type="file" size="32" name="my_field" value="" /></p>
<p class="button"><input type="hidden" name="action" value="image" />
<input type="submit" name="Submit" value="Upload" /></p>
</form>
</fieldset>
<?
;
}
}
?>
Hope someone can help.
Wayne.