0
I have an update/ folder with PHP files, so:
These are mysql update files, when it is updated soon after the server erases. When the client does not access the Admin the file stays there, when we release another update then adds the file of the previous version and the latest one and so on until it accesses the Admin to run this update.
My problem:
It is not running in ascending order. I need to make it always open from the smallest to the largest, because that is the order of the update.
Code:
<?php
$path = $_SERVER["DOCUMENT_ROOT"]."/update/";
$diretorio = dir($path); $i = 0;
while($i <= 3){
$arquivo = $diretorio -> read();
$file = explode("_v", $arquivo);
if ($file[0] == 'updateSQL'){
?>
<script type="text/javascript">$(function() {$('#myModal').modal('show');})</script>
<script type="text/javascript">$('#myModal').modal({backdrop: 'static',keyboard: false})</script>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Espere... Não feche até acabar.</h4>
</div>
<div class="modal-body">
<iframe src="../update/<?php echo $arquivo?>" frameborder="0" height="300px" width="100%" onload="resizeIframe(this);"></iframe>
</div>
</div>
</div>
</div>
<?php
}$i++;
}
$diretorio -> close();
?>
I just didn’t understand how to determine the location of the folder where you have the files, as in my example above.
– Tiago
In your script, you used an Apache dependent global variable.
$_SERVER["DOCUMENT_ROOT"]
. I do not recommend for this purpose. In the example I posted , I used the constant__DIR__
, which returns the current script directory. Just test the example.. Give aecho $base; exit;
to see the result. Easily you will realize and know how to implement what you need.– Daniel Omine
Thanks for the tip, I was able to understand, but it seems that there is a problem, the last file to be run is in the first value of the array that is ZERO. Behold
Array ( [1] => updateSQL_v419.php [2] => updateSQL_v420.php [3] => updateSQL_v421.php [0] => updateSQL_v422.php )
– Tiago
must have done something wrong.. Also note that there are different ways to do it. The central idea is to use the natcasesort() function to sort the array. It usually comes sorted alphabetically, but it’s good to use the function to make sure it’s really well ordered. As for the error you describe, I cannot evaluate without knowing what and how you are making your adaptation.
– Daniel Omine
I did as you informed
<?php 
$base = __DIR__.DIRECTORY_SEPARATOR."/update/";
$dir = dir($base);
while (false !== ($e = $dir->read()))
 if (is_file($base.$e)) 
 $f[] = $e;
natcasesort($f);
print_r($f);
?>
– Tiago
Ahhh got it.. Man.. Exit went right.. what happens is that the indexes of the array are preserved, but the order of them has been modified correctly. Note you even the output of print_r(). Despite having ZERO key, the value is in the last position.
– Daniel Omine
And what’s the solution to that? :)
– Tiago
how so? solution? is correct... rsrs
– Daniel Omine
is worried about how to do the loop loop? is that? if you use the foreach() why you won’t need to worry about the order of the keys.
– Daniel Omine
How do I display one file at a time? It has to be run one by one, I’m using the
foreach
to get the file name, but it displays all.– Tiago