php-general Digest 18 Sep 2007 15:34:35 -0000 Issue 5025
Topics (messages 262191 through 262202):
dir_object->read() on different platform
262191 by: news.php.net
262192 by: Jim Lucas
262193 by: Jim Lucas
262194 by: Jim Lucas
Re: Try to find a solution, when restart Apache with PHP Script
262195 by: Rodolfo De Nadai
Re: PHP "preg_replace" help
262196 by: Al
dynamic <img>
262197 by: Anugrah Widya
262199 by: Daniel Brown
262202 by: Anugrah Widya
Re: back-button question
262198 by: Al
Re: split in to multiple pages ( pagination)
262200 by: Joker7
Re: split in to multiple pages (I think)
262201 by: Joker7
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
Hi! I have some text and JPEG files inside a directory like:
1992-7-11.txt
1992-7-11_pic1.jpg
2000-4-10.txt
2000-4-10_pic1.jpg
2004-5-2.txt
2004-5-2_pic1.jpg
On a Windows box (XP + Apache), if I do a dir_object->read() for the
directory, read() reads the files above "in order" (eg.
1992-7-11.txt...2000-4-10.txt...2004-5-2.txt) even the time stamps on these
files are different.
However, after I ftp them to a Linux box and load the php script from the
Linux box, the order is gone. The time stamps on those files on the Linux
box are the same since they were all ftp and cp at the same time.
Does anyone know why? Can anyone suggest a simple solution?
Thanks.
Davis
--- End Message ---
--- Begin Message ---
news.php.net wrote:
Hi! I have some text and JPEG files inside a directory like:
1992-7-11.txt
1992-7-11_pic1.jpg
2000-4-10.txt
2000-4-10_pic1.jpg
2004-5-2.txt
2004-5-2_pic1.jpg
On a Windows box (XP + Apache), if I do a dir_object->read() for the
directory, read() reads the files above "in order" (eg.
1992-7-11.txt...2000-4-10.txt...2004-5-2.txt) even the time stamps on these
files are different.
However, after I ftp them to a Linux box and load the php script from the
Linux box, the order is gone. The time stamps on those files on the Linux
box are the same since they were all ftp and cp at the same time.
Does anyone know why? Can anyone suggest a simple solution?
Thanks.
Davis
Use glob() instead and then use sort() on the returned array.
That should put things back in order
<?php
$ar = glob('/dir/');
sort($ar);
# This should display the files in order
foreach ( $ar AS $file ) {
echo $file;
}
?>
Hope that helps
Jim
--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
news.php.net wrote:
Hi! I have some text and JPEG files inside a directory like:
1992-7-11.txt
1992-7-11_pic1.jpg
2000-4-10.txt
2000-4-10_pic1.jpg
2004-5-2.txt
2004-5-2_pic1.jpg
On a Windows box (XP + Apache), if I do a dir_object->read() for the
directory, read() reads the files above "in order" (eg.
1992-7-11.txt...2000-4-10.txt...2004-5-2.txt) even the time stamps on
these files are different.
However, after I ftp them to a Linux box and load the php script from
the Linux box, the order is gone. The time stamps on those files on
the Linux box are the same since they were all ftp and cp at the same
time.
Does anyone know why? Can anyone suggest a simple solution?
Thanks.
Davis
Use glob() instead and then use sort() on the returned array.
That should put things back in order
<?php
$ar = glob('/dir/');
sort($ar);
# This should display the files in order
foreach ( $ar AS $file ) {
echo $file;
}
?>
Hope that helps
Jim
forgot, you might need to use the extension, like so.
glob('/path/to/files/*.txt');
glob() does recognize '*' & '?' as multi & single char replacements.
Jim
--- End Message ---
--- Begin Message ---
news.php.net wrote:
Hi! I have some text and JPEG files inside a directory like:
1992-7-11.txt
1992-7-11_pic1.jpg
2000-4-10.txt
2000-4-10_pic1.jpg
2004-5-2.txt
2004-5-2_pic1.jpg
On a Windows box (XP + Apache), if I do a dir_object->read() for the
directory, read() reads the files above "in order" (eg.
1992-7-11.txt...2000-4-10.txt...2004-5-2.txt) even the time stamps on these
files are different.
However, after I ftp them to a Linux box and load the php script from the
Linux box, the order is gone. The time stamps on those files on the Linux
box are the same since they were all ftp and cp at the same time.
Does anyone know why? Can anyone suggest a simple solution?
Thanks.
Davis
but, to explain why it happens, it going to be like describing the
differences between *nix and windows.
Simply put, internally, they store file information differently and by
doing this differently, they display the file list differently.
Also, *nix file names are case sensitive and windows is not. Be careful
with this one, it will bite you at some point.
Jim
--- End Message ---
--- Begin Message ---
Daevid, understood... but in my case the php script is called once one
time, and then keep's on running "forever" on a server background shell...
The user never will have to worry about the process again, but if the
process is not running on the server a message will apear on the
interface or a email will be send to the administrator (me and others)...
The best solution for me will be the possibility of running this PHP
script on other port than the default using by apache.
Thanks
Daevid Vincent escreveu:
We put a timeout at the top and show an error if the server never comes
back. You could do whatever you want. As long as the user doesn't try to
refresh the page or go somewhere else on your server, the ajax will just
keep trying in the background. That's all client-side JS / AJAX.
-----Original Message-----
From: Rodolfo De Nadai [mailto:[EMAIL PROTECTED]
Sent: Monday, September 17, 2007 1:00 PM
To: Daevid Vincent
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Try to find a solution, when restart
Apache with PHP Script
Hi Daevid,
This app keep alive forever as well?
When you restart apache what happend to your app?
Daevid Vincent escreveu:
-----Original Message-----
From: Rodolfo De Nadai [mailto:[EMAIL PROTECTED]
Sent: Monday, September 17, 2007 5:25 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Try to find a solution, when restart Apache
with PHP Script
Hi all...
I'm facing a serious problem with my application. I have a
script write
in PHP that starts in Internet Explorer, this script keep
on running
until a varible value change on my MySQL database.
The problem is that when i restart Apache, the process child
initalized
isn't kill... then the apache can't be start because the
script is use
the port 80.
To solve my problem, without change anything, the best
would be that
when i execute the script, it run on other port than the
default 80...
so this way apache could start...
The is a way to redirect through php, so the script run on
a diferent
port?? Like change some line, or add on php.ini files?? or even in
programming??
thanks ... for any info
We do something like this, wherein sometimes we have to
force a restart of
Apache, so in order to not kill the web page for the GUI,
we use AJAX to
continually poll the server. Then when the server is back,
we can issue a
page refresh to whatever page we want...
---------------------------8< snip
8----------------------------------------
<?php
$request_interval = 10000; // 10 seconds.
$type = intval( $_GET[ 'type' ] );
if ( 1 == $type )
{
$initial_wait = 60000; // 1 minute.
$title = translate('Rebooting Appliance');
$text = translate('This may take several
minutes. If this
page does not redirect you, click <A
HREF="home_start_main.php">here</A>.');
}
else
{
$initial_wait = 20000; // 20 seconds.
$title = translate('Rebuilding Web Certificates');
$text = translate('If this page does not
redirect you in a
few seconds, click <A HREF="home_start_main.php">here</A>.');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE><?= translate('%1$s :: Loading...',
PRODUCT_fENF) ?></TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;">
<LINK REL="STYLESHEET" TYPE="text/css"
HREF="includes/default.css?version=1">
</HEAD>
<BODY>
<TABLE WIDTH="100%" HEIGHT="100%">
<TR>
<TD ALIGN="center" VALIGN="middle" HEIGHT="100%"
WIDTH="100%">
<TABLE BORDER="0" CLASS="componentBox">
<TR VALIGN="middle">
<TD COLSPAN="3"
CLASS="tableHeadline"><?=$title?></TD>
</TR>
<TR VALIGN="MIDDLE">
<TD><IMG
SRC="images/icons/paper_time.gif"></TD>
<TD>
<TABLE>
<TR>
<TD><?=$text?></TD>
</TR>
<TR>
<TD
ALIGN="CENTER"><DIV ID="status" STYLE="color:gray"><?=
translate('Waiting...') ?></DIV></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
var xmlhttp=false;
var id, state = 0;
var initial_wait = <?=$initial_wait?>;
// JScript gives us Conditional compilation, we can cope
with old IE versions.
// and security blocked creation of the objects.
try
{
xmlhttp = new ActiveXObject( "Msxml2.XMLHTTP" );
}
catch ( e )
{
try
{
xmlhttp = new ActiveXObject(
"Microsoft.XMLHTTP" );
}
catch ( E )
{
xmlhttp = false;
}
}
if ( !xmlhttp && typeof XMLHttpRequest != 'undefined' )
{
xmlhttp = new XMLHttpRequest();
}
function try_url()
{
if ( 0 == state )
{
document.getElementById( "status"
).innerHTML = "<?= translate('Requesting page...') ?>";
xmlhttp.open( "HEAD",
"home_start_main.php",
true );
xmlhttp.onreadystatechange=function()
{
state = xmlhttp.readyState
if ( 4 == state )
{
// Needed this try/catch
block for Firefox.
var httpstatus;
try
{
httpstatus =
xmlhttp.status;
}
catch ( e )
{
httpstatus = -1;
}
if( (
httpstatus == 200 ) ||
( httpstatus == null ) || ( httpstatus == 0 ) || (
httpstatus == 304 ) )
{
state = 0;
document.getElementById( "status" ).innerHTML = "<?=
translate('Request
succeeded...') ?>";
self.clearInterval(
id );
document.location =
'home_start_main.php';
}
else
{
document.getElementById( "status" ).innerHTML = "<?=
translate('Request
failed...') ?>";
state = 0;
}
}
}
xmlhttp.send( null )
}
}
function start_polling()
{
initial_wait = initial_wait - 1000;
if ( initial_wait <= 0 )
{
self.clearInterval( id );
document.getElementById( "status"
).innerHTML = "<?= translate('Requesting page...') ?>";
try_url();
id = self.setInterval( 'try_url()',
<?=$request_interval?> );
}
else
{
document.getElementById( "status"
).innerHTML = "<?= translate('Waiting ') ?>" + (
initial_wait / 1000 ) +
"...";
}
}
id = self.setInterval( 'start_polling()', 1000 );
//-->
</SCRIPT>
</BODY>
</HTML>
--
* Rodolfo De Nadai *
* Analista de Sistema Jr. - Desenvolvimento *
*Informática de Municípios Associados S.A.*
Seu governo mais inteligente
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> -
www.ima.sp.gov.br <http://www.ima.sp.gov.br/>
Fone: (19) 3739-6000 / Ramal: 1307
--
* Rodolfo De Nadai *
* Analista de Sistema Jr. - Desenvolvimento *
*Informática de Municípios Associados S.A.*
Seu governo mais inteligente
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> -
www.ima.sp.gov.br <http://www.ima.sp.gov.br/>
Fone: (19) 3739-6000 / Ramal: 1307
--- End Message ---
--- Begin Message ---
Just use stripslashes() on your submitted data and forget about testing for
magic_quotes. It's good practice anyhow. \" is not legit text regardless.
haim Chaikin wrote:
Hello,
I am a beginner in PHP. I need help with the function preg_replace.
I am trying to remove the backslashes ( \ ) from a string that is submitted
by the user.
It is submitted in a form but it adds \ before the quotation marks ( " ).
Will this change if I use the GET method instead of POST.
If not can you please tell me how to use preg_replace to remove the
backslashes.
Thank You,
Chaim Chaikin
Novice PHP programmer
Hotwire Band Website Administrator
http://hotwire.totalh.com
--- End Message ---
--- Begin Message ---
dear friends :),
i have problem with dynamic image displaying
here the snippets
thumb.php
<?php
header("Content-type: image/jpg");
$file = "data/original/filename.jpg";
readfile($file);
?>
img.php
<img src="thumb.php?filename.jpg" />
problem is i always get broken images, someone know how to fix this ?
thx in advance
anuwidy
--- End Message ---
--- Begin Message ---
Hello, Anugrah.
On 9/18/07, Anugrah Widya <[EMAIL PROTECTED]> wrote:
> i have problem with dynamic image displaying
>
> here the snippets
>
> thumb.php
> <?php
> header("Content-type: image/jpg");
> $file = "data/original/filename.jpg";
> readfile($file);
> ?>
>
> img.php
> <img src="thumb.php?filename.jpg" />
From your above examples, two questions come to mind:
1.) Is thumb.php in a folder above `data`? If not, adjust
your path accordingly.
2.) When using the query ?filename.jpg are you going to call
that as an $argv[1] variable? If you want to use it as a $_GET,
$_POST, or $_REQUEST, it will need a variable name with an assigned
value. For example:
<img src="thumb.php?img=filename.jpg">
L>thumb.php
<?
$path = "../data/original/"; // In case it's a same-level
directory as the PWD
$img = $_GET['img'];
header("Content-type: image/jpg");
readfile($path.$img);
?>
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Give a man a fish, he'll eat for a day. Then you'll find out he was
allergic and is hospitalized. See? No good deed goes unpunished....
--- End Message ---
--- Begin Message ---
Daniel Brown wrote:
Hello, Anugrah.
On 9/18/07, Anugrah Widya <[EMAIL PROTECTED]> wrote:
i have problem with dynamic image displaying
here the snippets
thumb.php
<?php
header("Content-type: image/jpg");
$file = "data/original/filename.jpg";
readfile($file);
?>
img.php
<img src="thumb.php?filename.jpg" />
From your above examples, two questions come to mind:
1.) Is thumb.php in a folder above `data`? If not, adjust
your path accordingly.
2.) When using the query ?filename.jpg are you going to call
that as an $argv[1] variable? If you want to use it as a $_GET,
$_POST, or $_REQUEST, it will need a variable name with an assigned
value. For example:
<img src="thumb.php?img=filename.jpg">
L>thumb.php
<?
$path = "../data/original/"; // In case it's a same-level
directory as the PWD
$img = $_GET['img'];
header("Content-type: image/jpg");
readfile($path.$img);
?>
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Give a man a fish, he'll eat for a day. Then you'll find out he was
allergic and is hospitalized. See? No good deed goes unpunished....
thank you Mr. Brown for your reply,
yep thumb.php and img.php are in the same level
correction for img.php
<img src="thumb.php?url=filename.jpg" />
i don't know what wrong with it, when i save the image data to another
files, the image didn;t corrupted, but when displayed dynamically it's
corrupted.., and the path are ok ;)
did i miss something on this, and i didn;t aware of it ?
--- End Message ---
--- Begin Message ---
The general rule is to create or maintain every page on your server of what you
what the client to see. Then send it for every submit. That way you don't have
to worry about satisfying every browser and configuration there is.
Πρεκατές Αλέξανδρος wrote:
I'a writing first time so sorry if i reapeat but
i wanted to say this in my own words and angle.
My question is :
Lets assume that we'r going throught php/html files
a-----> b ------> c
|<--------|
1)From a to b through a link
2)from b to c through a submit button (post method)
3) c is a php script which does some mysql queries and changes
some session variables and outputs a location header to
return to b.
While back in b we press the back button
when back button is pressed
my icewiesel browser gets me to 'a' page.
Trying to find some sense i postulated
that a browser holds in its history (for back/forward)
only requests made explicitly by the user and not the ones
made from withing php files (with header commands) .
Is my theory right..
I'm searching in the broader context of trying to control
how my bookstore website will react to random events from
the user (back/forward, links etc) while in a middle of
a series of php files that i want to act as a transaction.
Any help- recommendations for study on the subject would be very
welcomed. I have 3 books on mysql/php but that issues
r not examined,
Prekates Alexandros
Trikala Greece
--- End Message ---
--- Begin Message ---
In news: [EMAIL PROTECTED]
- Greg Donald wrote :
>> On Sat, 15 Sep 2007, Joker7 wrote:
>>> I'm using the code below to display news articles-which works great
>>> apart from. I can control the number of articles,but I would like
>>> to add a link to the bottom of the page to the un-displayed
>>> articles ( nexted 5 articles and so on) any pointers would be most
>>> welcome as most know my PHP skills are not the best :).
>>
>> <?
>>
>> $max_latest = 5;
>> $filename = "articlesum.php";
>>
>> #- open article
>> if(file_exists($filename)){
>> $fh = fopen($filename, "r");
>> $old_news = fread($fh, filesize($filename));
>> fclose($fh);
>> }
>> #- get article
>> $articles = explode("<!--ARTICLE-->", $old_news);
>>
>> $i=0;
>> foreach ( $articles as $article ){
>> if(count($articles)>$i){
>> if($max_latest >= $i++){
>> print $article;
>> }
>> }
>> }
>>
>>>
>> There's a bunch of how-tos and discussion on this topic already:
>>
>> http://google.com/search?q=php+pagination
>>
>> You have to manage a variable across page requests to keep track of
>> where you are. Use that variable in your SQL as part of your
>> offset/limit parameters.
>>
>>
>> --
>> Greg Donald
>> Cyberfusion Consulting
>> http://cyberfusionconsulting.com/
Thanks for the reply - I now know what it's called :)
I forgot to and it's a flat file system not the best but is ok for my needs.
I spent a couple of hours following link from google an not a sausage on
flat files :(
Chris
--- End Message ---
--- Begin Message ---
In news: [EMAIL PROTECTED] - Thomas Bachmann wrote :
>> Why don't post an example of your news file too?
>>
>> Joker7 schrieb:
>>> Hi,
>>> I'm using the code below to display news articles-which works great
>>> apart from. I can control the number of articles,but I would like
>>> to add a link to the bottom of the page to the un-displayed
>>> articles ( nexted 5 articles and so on) any pointers would be most
>>> welcome as most know my PHP skills are not the best :).
>>>
>>> Cheers
>>> Chris
>>>
>>>
>>> <?
>>>
>>> $max_latest = 5;
>>> $filename = "articlesum.php";
>>>
>>> #- open article
>>> if(file_exists($filename)){
>>> $fh = fopen($filename, "r");
>>> $old_news = fread($fh, filesize($filename));
>>> fclose($fh);
>>> }
>>> #- get article
>>> $articles = explode("<!--ARTICLE-->", $old_news);
>>>
>>> $i=0;
>>> foreach ( $articles as $article ){
>>> if(count($articles)>$i){
>>> if($max_latest >= $i++){
>>> print $article;
>>> }
>>> }
>>> }
Here you go Thomas- not mine I found it on the www.
Im sorry I started using this now would have been a lot better to use mysql.
Chris
<?
include ("template.inc");
include ("config.php");
$subject = $_POST[subject];
$summary = $_POST[summary];
$passwd = $_POST[passwd];
$date = $_POST[date];
$body = $_POST[body];
$article_id = $_POST[article_id];
#foreach($GLOBALS as $a => $b){ print "<li>$a => $b";}
$summary_template = "t_summary.tp";
$article_template = "t_article.tp";
$max_summary = 5;
function summary_page ($subject, $date, $summary, $article_id)
{
global $summary_template;
$t = new Template();
$t->set_file("SummaryPage", $summary_template);
$article_url = "article_".$article_id.".php";
$date = ($date);
$summary = nl2br($summary);
$t->set_var( array(
"subject" => $subject,
"date" => $date,
"summary" => $summary,
"article_url" => $article_url
));
$t->parse("Summary", "SummaryPage");
return $t->get_var("Summary");
}
function main_page ($subject, $date, $summary, $article_id, $body)
{
global $article_template;
$t = new Template();
$t->set_file("ArticlePage", $article_template);
$article_url = "article_".$article_id.".php";
$date =($date);
$summary =($summary);
$body =nl2br($body);
$t->set_var( array(
"subject" => $subject,
"date" => $date,
"summary" => $summary,
"body" => $body,
"article_url" => $article_url
));
$t->parse("Article", "ArticlePage");
return $t->get_var("Article");
}
function add_article($filename, $news)
{
if(file_exists($filename)){
$fh = fopen($filename, "r");
$old_news = fread($fh, filesize($filename));
fclose($fh);
}
/* TODO: Multipage articles
preg_match_all("<!--ARTICLE PAGE=(\d*)-->", $old_news, $matches;
if( count($matches[0]) >= $max_summary){
$oldfilename = $filename.($matches[0][0]+1);
}
*/
$fh = fopen($filename, "w");
$news = stripslashes($news);
fwrite($fh, "\n\n$news $old_news");
fclose($fh);
}
if(strcmp($subject, "")){
if(!(strcmp($passwd, $password))){
add_article("article_summary.php", summary_page($subject, $date,
$summary, $article_id));
add_article("article_$article_id.php", main_page($subject, $date,
$summary, $article_id, $body));
echo "<br><p><a href=article_$article_id.php>Article has been
added!</a></p>";
}else{
echo "<p><b> Password is wrong!</b></p>";
}
}
?>
<form action=news.php method=post>
<table border=0>
<tr> <td valign="top"><p class="header1">(Password):</p></td><td> <input
type=password name=passwd size=20> </td></tr>
<tr> <td valign="top"><p class="header1">Subject:</p></td><td> <input
type=text name=subject size=50> </td></tr>
<tr> <td valign="top"><p class="header1">Article ID:</p></td><td> <input
type=text name=article_id value=<? echo date("Y_m_j_is"); ?> size=30>
</td></tr>
<tr> <td valign="top"><p class="header1">Date/Author:</p></td><td> <textarea
name=date rows=2 cols=50 wrap=soft><? echo date("M j, Y\n"); ?>Author:
</textarea> </td></tr>
<tr> <td valign="top"><p class="header1">Summary:</p></td><td> <textarea
name=summary rows=5 cols=50 wrap=soft></textarea> </td></tr>
<tr> <td valign="top"><p class="header1">Body:</p></td><td> <textarea
name=body rows=15 cols=50></textarea> </td></tr>
</table><br>
<center><input type=submit name=submit value=Add-Article></center>
</form>
--
Cheap As Chips Broadband http://yeah.kick-butt.co.uk
Superb hosting & domain name deals http://host.kick-butt.co.uk
--- End Message ---