hi,
I've got this piece of coding which displays the images within a folder and allows me to add captions to the images using xml. the problem im having is once it reads the folder it is mixing the images up....instead of listing them in order like 1,2,3,4,5 it starts with 1 and then any number will follow. how can i stop it from doing this.
here is the code -
-
<center>
-
<table width="675px" border="0" cellspacing="5" cellpadding="5" align="center">
-
<tr>
-
<?php
-
$r = 0;
-
$pn=1;
-
$pto=1;
-
-
for($n=0; $n<$total_items; $n++) {
-
if($n !=0 && fmod($n, 5) == 0) {
-
echo "</tr><tr>";
-
}
-
$imageL= $path.$item[$n];
-
if (substr($imageL,-5) != 'b.jpg')
-
{
-
$img_path="http://theauctionwinners.com/resources/$imageL";
-
$editLink = "http://theauctionwinners.com/resources/imgEdit.php?img=$img_path";
-
$iframeName= 'if1';
-
$iframeHeight= '955px';
-
$click= 'onClick';
-
// display the item
-
echo '<td><center><p><a href="'.$img_path .'"><img src= "'.$path.$item[$n] .'" height="100" width="100"></a></p></center>';
-
echo '<center><p><input type="hidden" name="picT[]" value="pic'.$pn++.'"/></p></center>';
-
echo '<center><p><input type="hidden" name="photoT[]" value="PHOTO '.$pto++.'"/></p></center>';
-
echo '<center><p><input type="text" name="captionT[]" value=""/></p></center>';
-
echo '<center><p><a href="'.$editLink .'" '.$click.'="document.getElementById('.$iframeName .').height='.$iframeHeight .'; document.getElementById('.$iframeName .').src=this.href; return false;"> > Edit Image < </a></p></center><br></td>';
-
}
-
}
-
-
if($r>0) {
-
for($m=$r; $m<5; $m++) {
-
echo "<td> </td>";
-
}
-
}
-
-
?>
-
16 4087
how do you determine $item? as it looks, you're displaying the images in the order of the array. maybe some of the array sorting functions will help you.
i had to go through 3 tutorials to get this far with the code....where can i go for the array sorting functions tutorial?
start here. from there on it should not be too difficult.
ok asort() & ksort() seems to be a good and simple choice...from my coding which do i add asort() to?
asort($path.$item[$n]); or asort($item[$n]); ?
ksort($path.$item[$n]); or ksort($item[$n]); ? -
<?php
-
-
$path = "upload/$random_digit/images/"; // path to the directory to read ( ./ reads the dir this file is in)
-
if ($handle = opendir($path)) {
-
while (false !== ($file = readdir($handle))) {
-
if ($file != "." && $file != "..") {
-
if(!is_dir($file)){
-
$item[] = $file;
-
}
-
}
-
}
-
closedir($handle);
-
}
-
-
$total_items = count($item);
-
$max_items = ceil($total_items / 5); // items per <td>
-
$start = 0;
-
$end = $max_items
-
-
//generate the table
-
?>
-
-
-
<center>
-
<table width="675px" border="0" cellspacing="5" cellpadding="5" align="center">
-
<tr>
-
<?php
-
$r = 0;
-
$pn=1;
-
$pto=1;
-
-
for($n=0; $n<$total_items; $n++) {
-
if($n !=0 && fmod($n, 5) == 0) {
-
echo "</tr><tr>";
-
}
-
$imageL= $path.$item[$n];
-
if (substr($imageL,-5) != 'b.jpg')
-
{
-
$img_path="http://theauctionwinners.com/resources/$imageL";
-
$editLink = "http://theauctionwinners.com/resources/imgEdit.php?img=$img_path";
-
$iframeName= 'if1';
-
$iframeHeight= '955px';
-
$click= 'onClick';
-
// display the item
-
echo '<td><center><p><a href="'.$img_path .'"><img src= "'.$path.$item[$n] .'" height="100" width="100"></a></p></center>';
-
echo '<center><p><input type="hidden" name="picT[]" value="pic'.$pn++.'"/></p></center>';
-
echo '<center><p><input type="hidden" name="photoT[]" value="PHOTO '.$pto++.'"/></p></center>';
-
echo '<center><p><input type="text" name="captionT[]" value=""/></p></center>';
-
echo '<center><p><a href="'.$editLink .'" '.$click.'="document.getElementById('.$iframeName .').height='.$iframeHeight .'; document.getElementById('.$iframeName .').src=this.href; return false;"> > Edit Image < </a></p></center><br></td>';
-
}
-
}
-
-
if($r>0) {
-
for($m=$r; $m<5; $m++) {
-
echo "<td> </td>";
-
}
-
}
-
-
?>
-
</tr>
-
<td><tr><center><input name="create" type="submit" value="Submit" /></center></tr></td>
-
</form>
-
</table>
-
@anfetienne
as described in the manual entry, asort() expects an array as input. thus
i understand that but which is best for mine?
i just got an error from asort
Warning: asort() expects parameter 1 to be array, string given in /var/www/vhosts/theauctionwinners.com/httpdocs/resources/templateEdit.php on line 473
Warning: asort() expects parameter 1 to be array, string given in /var/www/vhosts/theauctionwinners.com/httpdocs/resources/templateEdit.php on line 473
Warning: asort() expects parameter 1 to be array, string given in /var/www/vhosts/theauctionwinners.com/httpdocs/resources/templateEdit.php on line 473
@anfetienne
well, ksort() will sort your array keys, which are already ordered, so it should not have any effect. @anfetienne
see post above
its just strange how it wont show the images in the correct order
except that "correct order" is very hard to teach a computer. do a var_dump() before and after sorting, so that you see how the sorting function actually sorts.
it sorts incorrectly.....the files are uploaded and renamed correctly but once it gets to reading the directory and putting it in table format it sorts incorrectly....have i done anything wrong in the coding?
where did you sort the array?
it's sorted in the only place where the array exists and thats when it's displayed....within the same coding i've posted
hi can anyone help me? i have tried sorting and i still can't get them to order correctly???
how are they ordered currently, and how would you like them to be?
they are ordering 1,3,2,4,6,5.....etc its all jumbled and i'd like them to be ordered 1,2,3,4,5,6,7,8
i've tried everything i could think of but can't get it to work.
is it possible to order images within a directory by their name rather than letting php just order it how it wants to?
this is my code -
<?php
-
-
$path = "upload/$random_digit/images/"; // path to the directory to read ( ./ reads the dir this file is in)
-
if ($handle = opendir($path)) {
-
while (false !== ($file = readdir($handle))) {
-
if ($file != "." && $file != "..") {
-
if(!is_dir($file)){
-
$item[] = $file;
-
}
-
}
-
}
-
closedir($handle);
-
}
-
-
$total_items = count($item);
-
$max_items = ceil($total_items / 5); // items per <td>
-
$start = 0;
-
$end = $max_items
-
-
//generate the table
-
?>
-
-
-
<center>
-
<table width="675px" border="0" cellspacing="5" cellpadding="5" align="center">
-
<tr>
-
<?php
-
$r = 0;
-
$pn=1;
-
$pto=1;
-
-
for($n=0; $n<$total_items; $n++) {
-
if($n !=0 && fmod($n, 5) == 0) {
-
echo "</tr><tr>";
-
}
-
$imageL= $path.$item[$n];
-
if (substr($imageL,-5) != 'b.jpg')
-
{
-
$img_path="http://theauctionwinners.com/resources/$imageL";
-
$editLink = "http://theauctionwinners.com/resources/imgEdit.php?img=$img_path";
-
$iframeName= 'if1';
-
$iframeHeight= '955px';
-
$click= 'onClick';
-
// display the item
-
echo '<td><center><p><a href="'.$img_path .'"><img src= "'.$path.$item[$n] .'" height="100" width="100"></a></p></center>';
-
echo '<center><p><input type="hidden" name="picT[]" value="pic'.$pn++.'"/></p></center>';
-
echo '<center><p><input type="hidden" name="photoT[]" value="PHOTO '.$pto++.'"/></p></center>';
-
echo '<center><p><input type="text" name="captionT[]" value=""/></p></center>';
-
echo '<center><p><a href="'.$editLink .'" '.$click.'="document.getElementById('.$iframeName .').height='.$iframeHeight .'; document.getElementById('.$iframeName .').src=this.href; return false;"> > Edit Image < </a></p></center><br></td>';
-
}
-
}
-
-
if($r>0) {
-
for($m=$r; $m<5; $m++) {
-
echo "<td> </td>";
-
}
-
}
-
-
?>
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ken Tech |
last post by:
Anybody know references about how to read active directory value from
asp.net
pretty urgent!
thanks,
Ken
|
by: Csaba Gabor |
last post by:
Not sure of best place for this question...
Are there any built in images within the browser that I can assume
(particularly IE and FF)?
More specifically, I am writing a one file webApp.php...
|
by: Andy |
last post by:
HI all,
I'm trying to read Active Directory from within an Asp.net application
which is not impersonating any domain user.
I'd like to allow the site to query the Active directory, but I want...
|
by: gencode |
last post by:
I need to make a javascript read a web directory from a remote site (ie
"http://remotesite.com/images")
(The remote die does not have an index.htm and does have directory
listing enabled)
I...
|
by: Michael Malinowski |
last post by:
Is there a way to read the directory that the currently running python file
is located in?
Cheers
Mike.
|
by: Salimunnisaa |
last post by:
Hi all,
Pls tell me how to read images from sql server database in asp.net. This is very urgent.
|
by: wstsoi |
last post by:
hi
I have to read images from spreadsheet, is it possible to do with php?
|
by: Anjan Bhowmik |
last post by:
Hi,
I use a form to upload an image to a directory on my site
(~/Images/UserName/file1.jpg). Using Server.mapPath function i get the
Physical path and save the file using...
|
by: bluewavessurf |
last post by:
I want to implement a Perl Program that takes a directory path, ex (d:\programs) as an INPUT and this directory could have multiple files for this program let’s say 5 files (doc1, doc2, doc3, doc4,...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |