php-general Digest 22 May 2006 00:22:54 -0000 Issue 4141

Topics (messages 236570 through 236592):

Re: IP to country DB and script
        236570 by: Kevin Davies
        236571 by: Kevin Davies
        236573 by: Ryan A
        236577 by: tedd
        236579 by: Ryan A
        236581 by: tedd
        236583 by: Ryan A
        236587 by: tedd
        236588 by: Ryan A

detect if file exist
        236572 by: Alain Roger
        236574 by: Ryan A
        236575 by: Rabin Vincent
        236576 by: Rabin Vincent
        236578 by: Ryan A
        236586 by: tedd

it don´t works fine.
        236580 by: João Cândido de Souza Neto
        236582 by: João Cândido de Souza Neto
        236584 by: João Cândido de Souza Neto

Re: Date() finding yesterday
        236585 by: Scott Hurring

Re: Uploading Files
        236589 by: tedd

php transparent proxy
        236590 by: IraqiGeek

Re: Uploading Files - Beginner
        236591 by: P. Guethlein
        236592 by: Jay Blanchard

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:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
<snip>
Can anybody recommend a IP to country (or better still
IP->city) database and script?
</snip>


Ryan,

I've used Tracewatch (a web stats package) on a couple of sites, and it
comes with a CSV of IP to Country conversions I believe.

URL: www.tracewatch.com

HTH,

Kev

--- End Message ---
--- Begin Message ---
<snip>
URL: www.tracewatch.com
</snip>

Seems like their data is sourced from here:
http://ip-to-country.webhosting.info/

--- End Message ---
--- Begin Message ---
Thanks Kevin,

Will look into it, I think I found the same link via
the SEs...am not sure though.

Cheers!
Ryan

--- Kevin Davies <[EMAIL PROTECTED]> wrote:

> <snip>
> URL: www.tracewatch.com
> </snip>
> 
> Seems like their data is sourced from here:
> http://ip-to-country.webhosting.info/
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message ---
At 4:59 AM -0700 5/21/06, Ryan A wrote:
Hey,

Can anybody recommend a IP to country (or better still
IP->city) database and script? I have found some leads
via google but would like to know what you guys are
using or can recommend.

Or just the DB would do, I can write the script if I
have to.

Thanks!
Ryan

Ryan:

You might want to review:

http://www.weberdev.com/get_example-3091.html

I also have:

http://xn--ovg.com/location

If you want that, please let me know and I'll provide. From reported tests, it appears to be correct most of the time.

hth's

tedd
--
------------------------------------------------------------------------------------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Hey Tedd,

> Ryan:
> 
> You might want to review:
> 
> http://www.weberdev.com/get_example-3091.html

Thanks for the link.

 
> I also have:
> 
> http://xn--ovg.com/location
> 
> If you want that, please let me know and I'll
> provide.

As usual, most generious, thanks for the offer.
I'm still testing 3 that I found, if they dont go well
will take you up on your offer.

I have found quite a few ip-> country scripts/DBs (one
extra with help from Kevin from the list) but unable
to find any ip->city that is not commercial...the only
one everyone seems to be promoting is ip2location
which is $199

Any idea of a free one? If no, will continue with the
ip->country instead of city.

Thanks!
Ryan

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message ---
At 10:43 AM -0700 5/21/06, Ryan A wrote:
Hey Tedd,

 Ryan:

 You might want to review:

 http://www.weberdev.com/get_example-3091.html

Thanks for the link.


 I also have:

 http://xn--ovg.com/location

 If you want that, please let me know and I'll
 provide.

As usual, most generious, thanks for the offer.
I'm still testing 3 that I found, if they dont go well
will take you up on your offer.

I have found quite a few ip-> country scripts/DBs (one
extra with help from Kevin from the list) but unable
to find any ip->city that is not commercial...the only
one everyone seems to be promoting is ip2location
which is $199

Any idea of a free one? If no, will continue with the
ip->country instead of city.

Thanks!
Ryan


Ryan:

As always in life, your choices are quick, good, and inexpensive -- but you can only pick two. :-)

In any event, if you find a "free one" better than what I provided, please share.

tedd
--
------------------------------------------------------------------------------------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Hey Tedd,

> 
> As always in life, your choices are quick, good, and
> inexpensive -- 
> but you can only pick two. :-)

Hey! Thats a good one, am going to use it in other
places :-)
 Thanks!


> In any event, if you find a "free one" better than
> what I provided,  please share.

Will do, the problem is, when I visited that page it
tells me:
Your location:
city (unknown)
Country: EU

and gives me an option to identify myself below... I
did, so it will help you expand your db, but I cant
want to ask the visitors to my clients site to do the
same, it has to show them their correct country a high
percentage of the time.

After submitting my location details I went back there
and refreshed the page but it still shows me the same
old data....

Cheers!
Ryan

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message ---
At 11:01 AM -0700 5/21/06, Ryan A wrote:
 > As always in life, your choices are quick, good, and
 inexpensive --
 but you can only pick two. :-)

Hey! Thats a good one, am going to use it in other
places :-)
 Thanks!

No problem -- I met with a client yesterday where I told him that. He thought it a good quote as well, but let's see if he hires me. :-)

 > In any event, if you find a "free one" better than
 what I provided,  please share.

Will do, the problem is, when I visited that page it
tells me:
Your location:
city (unknown)
Country: EU

That routine doesn't reference a dB-- it simply uses:

$location = get_location_xml( get_remote_ip() );
$city = parse_city( $location );
$country = parse_country( $location );

No big deal -- just something I found interesting.

and gives me an option to identify myself below... I
did, so it will help you expand your db, but I cant
want to ask the visitors to my clients site to do the
same, it has to show them their correct country a high
percentage of the time.

After submitting my location details I went back there
and refreshed the page but it still shows me the same
old data....

Yep, but you're expecting more from me than what I deserve.

I could collect the data and build my own dB -- that sounds reasonable. But, my test here was simply to see how valid those calls were. I have no idea if the people who are submitting data to me are telling the truth or not. As such, it would be problematic to build a reliable dB from the "few" visitors I receive.

Plus, things change. Sometimes I access my site and it shows my correct location of "Lansing, MI", then other times is shows "Jackson, MI", and today it's showing "Unknown, CA". So, even if I were being honest, what would I report?

I have seen some pretty accurate reporting systems, but I fear that they have to be kept current on a daily basis.

tedd

--
------------------------------------------------------------------------------------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---

--- tedd <[EMAIL PROTECTED]> wrote:
Hey,

> At 11:01 AM -0700 5/21/06, Ryan A wrote:
> >  > As always in life, your choices are quick,
> good, and
> >>  inexpensive --
> >>  but you can only pick two. :-)
> >
> >Hey! Thats a good one, am going to use it in other
> >places :-)
> >  Thanks!
> 
> No problem -- I met with a client yesterday where I
> told him that. He 
> thought it a good quote as well, but let's see if he
> hires me. :-)

Best of luck, I hope you get it.



> 
> That routine doesn't reference a dB-- it simply
> uses:
> 
> $location = get_location_xml( get_remote_ip() );
> $city = parse_city( $location );
> $country = parse_country( $location );


Interesting....

 
> I have seen some pretty accurate reporting systems,
> but I fear that 
> they have to be kept current on a daily basis.

I guess so too, some companies are charging 199 for
the database (ip->country and city) and $280 for 1
year of updates.

The (free) package i downloaded references the DB and
so far its been pretty accurate (only ip-> country
though), i also checked it with some known proxies
(Korea, Japan, China and the US) and its been spot on
so far.

I can send it to you if you want, I had to tweak the
script a bit due to inconsistant variable names and
globals being off on my machine but it works great
now. Feel free to reply to me if you want it. Its just
under 3mb with the country csv file.

Cheers!

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message ---
Hi,

i have 1 folder, in this folder sometime a file can be sometimes not...

1. i would like to detect if the folder contains a file or not.
only 1 file can be in this folder but i do not know the name of this file,
and the extension should be xls.


when this file exists, i want to display the contents of this file to my web
site, how can i do it ?
2. could you advise me on some good tutorial PHP+Excel ?

thanks a lot,
Alain

--- End Message ---
--- Begin Message ---
Ummmm file_exists() ?

A simple search on the search engines for "php file
exists" gave me loads of results...

Dude, dont be lazy and just post here or you are going
to get a lot of grief...do a search on web then come
back if you dont find anything or have questions...

And trust me, this is one of the more polite answer
you will get or would have gotten.

-Ryan


--- Alain Roger <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> i have 1 folder, in this folder sometime a file can
> be sometimes not...
> 
> 1. i would like to detect if the folder contains a
> file or not.
> only 1 file can be in this folder but i do not know
> the name of this file,
> and the extension should be xls.
> 
> 
> when this file exists, i want to display the
> contents of this file to my web
> site, how can i do it ?
> 2. could you advise me on some good tutorial
> PHP+Excel ?
> 
> thanks a lot,
> Alain
> 


------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message ---
On 5/21/06, Alain Roger <[EMAIL PROTECTED]> wrote:
i have 1 folder, in this folder sometime a file can be sometimes not...

1. i would like to detect if the folder contains a file or not.
only 1 file can be in this folder but i do not know the name of this file,
and the extension should be xls.

Use the glob function: php.net/glob. Something like:

$f = glob('*.xls');
if ( count($f) )
$file = $f[0];
else
 die('no file');

Rabin

--- End Message ---
--- Begin Message ---
On 5/21/06, Ryan A <[EMAIL PROTECTED]> wrote:
Ummmm file_exists() ?

file_exists doesn't help here since the filename of
the file is not known. glob or the *dir functions do
the trick.

Rabin

[please bottom-post...]
A simple search on the search engines for "php file
exists" gave me loads of results...

Dude, dont be lazy and just post here or you are going
to get a lot of grief...do a search on web then come
back if you dont find anything or have questions...

And trust me, this is one of the more polite answer
you will get or would have gotten.

-Ryan


--- Alain Roger <[EMAIL PROTECTED]> wrote:

> Hi,
>
> i have 1 folder, in this folder sometime a file can
> be sometimes not...
>
> 1. i would like to detect if the folder contains a
> file or not.
> only 1 file can be in this folder but i do not know
> the name of this file,
> and the extension should be xls.
>
>
> when this file exists, i want to display the
> contents of this file to my web
> site, how can i do it ?
> 2. could you advise me on some good tutorial
> PHP+Excel ?
>
> thanks a lot,
> Alain

--- End Message ---
--- Begin Message ---
> On 5/21/06, Ryan A <[EMAIL PROTECTED]> wrote:
> > Ummmm file_exists() ?
> 
> file_exists doesn't help here since the filename of
> the file is not known. glob or the *dir functions do
> the trick.
> 
> Rabin
> 

Its all connected, had you searched the SEs first,
your would have found file_exists(), then if you read
that functions page at php.net you would have seen
readdir() which is another way of doing exactly what
you want..

eg:
readdir, if the directory is populated you can then
check the extention (eg: .com, php, xls or whatever)

All I am saying is, try to use the list as pretty much
your last resort..



------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message ---
At 3:52 PM +0200 5/21/06, Alain Roger wrote:
Hi,

i have 1 folder, in this folder sometime a file can be sometimes not...

1. i would like to detect if the folder contains a file or not.
only 1 file can be in this folder but i do not know the name of this file,
and the extension should be xls.


when this file exists, i want to display the contents of this file to my web
site, how can i do it ?
2. could you advise me on some good tutorial PHP+Excel ?

thanks a lot,


Alain:

I know you asked for a reference, but you might try this.

Replace "tmp" with path/to/your/folder.

The routine will look for files in the indicated folder. If there are no files present, then nothing happens -- however, if there are any files present, then it will fill the file_array with their names. From that, it will look at the files within that array and select out only those with the proper suffixes and fill the html array. Then it will read in from the html array and list the contents of those files to your web page.

This should do what you want.

<?php

$path = "tmp";
if ($handle = opendir($path))
        {
        while (false !== ($file = readdir($handle)))
                {
                if ($file != "." && $file != "..")
                        {
                        $file_array[] = $file;
                        if(eregi("(\.xml|\.html|\.htm|\.php|\.txt)", $file))
                                {
                                $html[] = $file;
                                }
                        }
                }
        closedir($handle);
        }

if (isset($file_array))
        {
        echo ("<br/>---- all files in dir");
        echo ("<pre>");
        print_r($file_array);
        echo("</pre>");

        echo ("<br/>---- selected files in dir");
        echo ("<pre>");
        print_r($html);
        echo("</pre>");

        if($html != null)
                {
                sort($html);
                foreach($html as $html => $value)
                        {
                        $filename = $path . "/" . $value;
                        $filesize = filesize($filename);
                        $file = fopen( $filename, "r" );
                        $text = fread( $file, $filesize );
                        fclose( $file );
                        echo( "<br/>File read: $filename<br/> ");
                        echo( "File Size: $filesize bytes<br/>" );
                        echo( "File Content:$text<br/>" );
                        }
                }
        }
else
        {
        echo ("<br/>---- nothing to read");
        }
?>

hth's

tedd


--
------------------------------------------------------------------------------------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Hi everyone.

I´m with a big trouble using php 5 + iis 5.1 in windows xp professional.

It was working fine, but suddenly stop working.
under my root folder i´ve got a system folder that run php-cgi.exe fine, but 
files under this folder (e.g. system/function/function1.php) isn´t 
recognised as a php file and the browse try to open it in dreamweaver or 
download it.

Saomeone here knows wath to do in this case?

Any tip´ll be appreciated.

Thanks

João Cândido de Souza Neto. 

--- End Message ---
--- Begin Message ---
It´s incredible.

As soon as i wrote this message, it beguns to work fine.

thanks everyone.

""João Cândido de Souza Neto"" <[EMAIL PROTECTED]> escreveu na 
mensagem news:[EMAIL PROTECTED]
> Hi everyone.
>
> I´m with a big trouble using php 5 + iis 5.1 in windows xp professional.
>
> It was working fine, but suddenly stop working.
> under my root folder i´ve got a system folder that run php-cgi.exe fine, 
> but files under this folder (e.g. system/function/function1.php) isn´t 
> recognised as a php file and the browse try to open it in dreamweaver or 
> download it.
>
> Saomeone here knows wath to do in this case?
>
> Any tip´ll be appreciated.
>
> Thanks
>
> João Cândido de Souza Neto. 


--- End Message ---
--- Begin Message ---
It´s incredible.

As soon as i wrote this message, it beguns to work fine.

thanks everyone.


""João Cândido de Souza Neto"" <[EMAIL PROTECTED]> escreveu na 
mensagem news:[EMAIL PROTECTED]
> Hi everyone.
>
> I´m with a big trouble using php 5 + iis 5.1 in windows xp professional.
>
> It was working fine, but suddenly stop working.
> under my root folder i´ve got a system folder that run php-cgi.exe fine, 
> but files under this folder (e.g. system/function/function1.php) isn´t 
> recognised as a php file and the browse try to open it in dreamweaver or 
> download it.
>
> Saomeone here knows wath to do in this case?
>
> Any tip´ll be appreciated.
>
> Thanks
>
> João Cândido de Souza Neto. 

--- End Message ---
--- Begin Message ---
mktime also works: http://php.net/mktime:

date("Y-m-d", mktime( ... ))

On 5/21/06, Rabin Vincent <[EMAIL PROTECTED]> wrote:

On 5/21/06, John Taylor-Johnston
<[EMAIL PROTECTED]> wrote:
> I cannot seem to get this right. How can I produce yesterday?
>
> $today = date("Y-m-d");
> $yesterday = date("Y-m-") . date("d")-1;
> $yesterday = date("Y-m-d")-1;
> $yesterday = date("Y-m-"."d"-1);
>
> I've been looking at the manual :) ...

Use php.net/strtotime:

$yesterday = date('Y-m-d', strtotime('-1 day'));

Rabin

--
http://rab.in

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
Scott Hurring [scott dot hurring dot lists at gmail dot com]
http://hurring.com/

--- End Message ---
--- Begin Message ---
At 1:52 AM -0700 5/21/06, P. Guethlein wrote:
I'm at one of those frustration levels.... can't seem to get a script working that will post and upload a file to the server. I"m working with the below. Can you help?

Guethlein:

Yes, try this -- watch for line breaks. Also, create folders "uploads/tmp".

The code works "as is" for me except that I have to give the "tmp" folder 0777 permissions* because the code runs as "nobody". I haven't figured out how to get around that, but I can change the uploaded file's permissions without error. (If anyone wants to show me OFF-LIST how to do this without setting the tmp folder to 0777, I'm all ears, but don't beat me up because I'm trying to learn.)

Code follows:

<?php

// This allows users to upload files to the server.

if (isset($_POST['submit'])) // handle the form -- start of main Submit conditional..
        {

        // Create the file name.

        $filename = $_FILES['upload']['name'];
        $file_loaded = 0;

        // Move the file over.

if (move_uploaded_file($_FILES['upload']['tmp_name'], "uploads/tmp/$filename"))
                {
                echo '<p>The file has been uploaded to the server.</p>';
                chmod("uploads/tmp/$filename", 0755);
                echo ( '<p>' . $filename . '</p>' );
                }
        else
                {
echo ('<p><font color="red">ERROR: The file was not upload.</font></p>');
                }
        }
else
        {

        ?>

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                <p>
                <input type="hidden" name="MAX_FILE_SIZE" value="30000">
                </p>
                <fieldset>
                <legend>Select the file to upload:</legend>
                <p>
                <b>File:</b>
                <input type="file" name="upload" />
                </p>
                </fieldset>
                <p>
                <input type="submit" name="submit" value="Submit" />
                </p>
        </form>

        <?php
        }
?>

hth's

tedd

* Larry Ullman in his books says to use 0777 permission for uploading files. However, he does say that it is less secure and should be placed outside of the web directory.
--
------------------------------------------------------------------------------------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Hi all,

Is anyone aware of a php script that runs as a proxy (not a web proxy)? I have a hosting account with a dedicated IP, and I'm wondering if I can use this account to run a proxy where I enter my account's dedicated IP in the browser as a proxy, and use that to surf the net.

I am already running a web proxy, but want to expand to be able to use the proxy with other applications.


Regards,
IraqiGeek
www.iraqigeek.com

Whoever undertakes to set himself up as judge in the field of truth and knowledge is shipwrecked by the laughter of the Gods. Albert Einstein
--- End Message ---
--- Begin Message --- I'm still very frustrated trying to figure out how to upload a file. I must have tried 15 different coding examples and none of them work.

When I try and debug and do a
print_r($_FILES);

All I'm getting back is array() with no data.

File upload is allowed in my php.ini

Can anyone offer any other insight before my laptop sails into the wall ?<smile>

Thanks, -Pete




At 02:03 PM 05/21/2006, tedd wrote:
At 1:52 AM -0700 5/21/06, P. Guethlein wrote:
I'm at one of those frustration levels.... can't seem to get a script working that will post and upload a file to the server. I"m working with the below. Can you help?

Guethlein:

Yes, try this -- watch for line breaks. Also, create folders "uploads/tmp".

The code works "as is" for me except that I have to give the "tmp" folder 0777 permissions* because the code runs as "nobody". I haven't figured out how to get around that, but I can change the uploaded file's permissions without error. (If anyone wants to show me OFF-LIST how to do this without setting the tmp folder to 0777, I'm all ears, but don't beat me up because I'm trying to learn.)

Code follows:

<?php

// This allows users to upload files to the server.

if (isset($_POST['submit'])) // handle the form -- start of main Submit conditional..
{

// Create the file name.

$filename = $_FILES['upload']['name'];
$file_loaded = 0;

// Move the file over.

if (move_uploaded_file($_FILES['upload']['tmp_name'], "uploads/tmp/$filename"))
 {
 echo '<p>The file has been uploaded to the server.</p>';
 chmod("uploads/tmp/$filename", 0755);
 echo ( '<p>' . $filename . '</p>' );
 }
else
 {
 echo ('<p><font color="red">ERROR: The file was not upload.</font></p>');
 }
}
else
{

?>

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 <p>
 <input type="hidden" name="MAX_FILE_SIZE" value="30000">
 </p>
 <fieldset>
 <legend>Select the file to upload:</legend>
 <p>
 <b>File:</b>
 <input type="file" name="upload" />
 </p>
 </fieldset>
 <p>
 <input type="submit" name="submit" value="Submit" />
 </p>
</form>

<?php
}
?>

hth's

tedd

* Larry Ullman in his books says to use 0777 permission for uploading files. However, he does say that it is less secure and should be placed outside of the web directory.
--
------------------------------------------------------------------------------------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
[snip]
I'm still very frustrated trying to figure out how to upload a 
file.  I must have tried 15 different coding examples and none of them
work.

When I try and debug and do a
print_r($_FILES);

All I'm getting back is array() with no data.

File upload is allowed in my php.ini

Can anyone offer any other insight before my laptop sails into the 
wall ?<smile>
[/snip]

Have you tried the very simple example shown in the manual?
http://us3.php.net/manual/en/features.file-upload.php

I will be right by my computer for a while, so make sure to reply to the
list. Pay particular attention to MAX_FILE_SIZE. Even if file upload is
allowed in you php.in are you running in safe mode?

--- End Message ---

Reply via email to