[PHP] Re: file_exists fun

2011-12-02 Thread Dee Ayy
On Fri, Dec 2, 2011 at 1:30 PM, Dee Ayy  wrote:
> The following code:
>
>                        $new_file = 
> ADS_DIR_INTERNAL.'/'.$ad_info['id'].'_'.$ad_info['filename'];
>                        echo "NEW_FILE:[".$new_file."]\n";
>                        echo "file_exists Using 
> VAR:[".file_exists($new_file)."]\n";
>                        echo "file_exists Using Hard
> Coded:[".file_exists('/home/fx/pads/ads_dir/1_rubik1920x1080lu0.jpg')."]\n";
>
> Gives this output:
> NEW_FILE:[/home/fx/pads/ads_dir/1_rubik1920x1080lu0.jpg]
> file_exists Using VAR:[]
> file_exists Using Hard Coded:[1]
>
> Why does it not work when using the variable in file_exists?
>
> I thought I may need some safe_mode magic, safe_mode_include_dir, or
> disable_functions, but I don't see any restrictions AND why does it
> work when it is hard coded?
> Warning
> This function returns FALSE for files inaccessible due to safe mode
> restrictions. However these files still can be included if they are
> located in safe_mode_include_dir.
>
> Current logic needs the following functions:
> file_exists
> md5_file
> move_uploaded_file
>
> Thanks.

>From PHP, exec('whoami') says "www-data", so I created /home/www-data
and chown to www-data.
file_exists with a variable still fails.
Initial and future testing of !file_exists(ADS_DIR_INTERNAL) works to
create the directory only once as intended, however ONLY initial
creation of the file inside the directory works with
move_uploaded_file.
Attempting to overwrite an existing file with move_uploaded_file fails.
I then tried exec('mv '.$_FILES['my_file']['tmp_name'].' '.$new_file)
as well as mv -f
which DOES COPY the filename of tmp_name to the correct directory
ADS_DIR_INTERNAL, but keeps the tmp_name filename!  It is not renamed
as a true linux "mv".
I assume it is some protection due to being an uploaded file.

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



Re: [PHP] Re: file_exists and wildcard/regex

2008-12-09 Thread German Geek
On Wed, Dec 10, 2008 at 1:13 PM, Stut <[EMAIL PROTECTED]> wrote:

>
> On 9 Dec 2008, at 23:24, Daniel Kolbo wrote:
>
>  Maciek Sokolewicz wrote:
>>
>>> Daniel Kolbo wrote:
>>>
 What is the preferred method with php to test and see if a file
 [pattern] exists?

 For example, i only need to search in one directory, that may have any
 number of files named such as afile1.txt, afile2.txt, afile3.txt,   And
 also, bfile1.txt, bfile2.txt, bfile3.txt, ...
 I want to see if any such file 'family' exists.  That is, i want to see
 if there is any file named bfile[1-9][0-9]+.txt.  I don't care which bfile
 number exists, i just want to know if any bfile exists.

 I hope this is clear enough, if not let me know.

 thanks,
 dK


>>> glob()
>>>
>>> http://www.php.net/glob
>>>
>> How portable is glob?
>> How fast is glob?  Being that it searches through the entire filesystem,
>> this could potentially take a long time (like if  i have wildcards early in
>> the filepath pattern and lots of matches) correct?  If my file variations
>> (wildcards) are just at the end of of the filepaths and i don't have more
>> than 1000 files in the directory then will I most likely be 'alright' with
>> glob (in terms of time)?  I have probably spent more time now 'considering'
>> the time implications of glob, than glob actually would consume when
>> operating...
>>
>> Thanks for the quick response/solutions.
>> dK
>>
>
> Glob works on all platforms.
>
> Glob does suffer from performance issues above a certain number of files,
> and this can be system dependant. If you're unsure how many files it may
> return you'd be better using opendir/readdir.
>
> Not sure where you got the idea that glob searches the entire file system,
> but it's limited to either the current working directory or the directory
> you specify. So if your PHP file is in /var/www/htdocs and you do
> glob('*.txt') you'll get all .txt files in /var/www/htdocs. And if you do
> glob('/tmp/*.txt') you'll get all .txt files in /tmp.
>
> -Stut
>
> --
> http://stut.net/
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I wrote my own little function for a regex pattern match on files:
class FileHandle {
public static function copyReg($srcDir, $destDir, $regEx, $mkdir =
false) {
  // ensure we have the right dir separator /(unix) \(win) and not at
the end
  $srcDir = rtrim(str_replace(array('/','\\'), DIRECTORY_SEPARATOR,
$srcDir), DIRECTORY_SEPARATOR);
  $destDir = rtrim(str_replace(array('/','\\'), DIRECTORY_SEPARATOR,
$destDir), DIRECTORY_SEPARATOR);
  //echo "DEST: ". $destDir ." END";
  if ($mkdir && !is_dir($destDir)) mkdir($destDir, 0777, true); //make
dir if not exists and mkdir
if ($handle = opendir($srcDir)) {
while (false !== ($file = readdir($handle))) {
//echo "$file\n";
preg_match($regEx, $file, $matches);
if ($file != '.' && $file != '..' && count($matches) > 0) {
  //print("$regEx $srcDir $file \n=".
print_r($matches,true));
copy($srcDir . DIRECTORY_SEPARATOR . $file,
$destDir . DIRECTORY_SEPARATOR . $file);
}
}
return true;
}
return false;
}
}

Hope that helps. Don't know how good this will perform.


-- 
Tim-Hinnerk Heuer

http://www.ihostnz.com -- Web Design, Hosting and free Linux Support


Re: [PHP] Re: file_exists and wildcard/regex

2008-12-09 Thread Stut


On 9 Dec 2008, at 23:24, Daniel Kolbo wrote:


Maciek Sokolewicz wrote:

Daniel Kolbo wrote:
What is the preferred method with php to test and see if a file  
[pattern] exists?


For example, i only need to search in one directory, that may have  
any number of files named such as afile1.txt, afile2.txt,  
afile3.txt,   And also, bfile1.txt, bfile2.txt, bfile3.txt, ...
I want to see if any such file 'family' exists.  That is, i want  
to see if there is any file named bfile[1-9][0-9]+.txt.  I don't  
care which bfile number exists, i just want to know if any bfile  
exists.


I hope this is clear enough, if not let me know.

thanks,
dK



glob()

http://www.php.net/glob

How portable is glob?
How fast is glob?  Being that it searches through the entire  
filesystem, this could potentially take a long time (like if  i have  
wildcards early in the filepath pattern and lots of matches)  
correct?  If my file variations (wildcards) are just at the end of  
of the filepaths and i don't have more than 1000 files in the  
directory then will I most likely be 'alright' with glob (in terms  
of time)?  I have probably spent more time now 'considering' the  
time implications of glob, than glob actually would consume when  
operating...


Thanks for the quick response/solutions.
dK


Glob works on all platforms.

Glob does suffer from performance issues above a certain number of  
files, and this can be system dependant. If you're unsure how many  
files it may return you'd be better using opendir/readdir.


Not sure where you got the idea that glob searches the entire file  
system, but it's limited to either the current working directory or  
the directory you specify. So if your PHP file is in /var/www/htdocs  
and you do glob('*.txt') you'll get all .txt files in /var/www/htdocs.  
And if you do glob('/tmp/*.txt') you'll get all .txt files in /tmp.


-Stut

--
http://stut.net/

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



Re: [PHP] Re: file_exists and wildcard/regex

2008-12-09 Thread Chris

Daniel Kolbo wrote:

Maciek Sokolewicz wrote:

Daniel Kolbo wrote:
What is the preferred method with php to test and see if a file 
[pattern] exists?


For example, i only need to search in one directory, that may have 
any number of files named such as afile1.txt, afile2.txt, afile3.txt, 
  And also, bfile1.txt, bfile2.txt, bfile3.txt, ...
I want to see if any such file 'family' exists.  That is, i want to 
see if there is any file named bfile[1-9][0-9]+.txt.  I don't care 
which bfile number exists, i just want to know if any bfile exists.


I hope this is clear enough, if not let me know.

thanks,
dK



glob()

http://www.php.net/glob

How portable is glob?
How fast is glob?  Being that it searches through the entire filesystem, 
this could potentially take a long time (like if  i have wildcards early 
in the filepath pattern and lots of matches) correct?  If my file 
variations (wildcards) are just at the end of of the filepaths and i 
don't have more than 1000 files in the directory then will I most likely 
be 'alright' with glob (in terms of time)?  I have probably spent more 
time now 'considering' the time implications of glob, than glob actually 
would consume when operating...


glob('/path/to/folder/*.txt');

--
Postgresql & php tutorials
http://www.designmagick.com/


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



[PHP] Re: file_exists and wildcard/regex

2008-12-09 Thread Daniel Kolbo

Maciek Sokolewicz wrote:

Daniel Kolbo wrote:
What is the preferred method with php to test and see if a file 
[pattern] exists?


For example, i only need to search in one directory, that may have 
any number of files named such as afile1.txt, afile2.txt, afile3.txt, 
  And also, bfile1.txt, bfile2.txt, bfile3.txt, ...
I want to see if any such file 'family' exists.  That is, i want to 
see if there is any file named bfile[1-9][0-9]+.txt.  I don't care 
which bfile number exists, i just want to know if any bfile exists.


I hope this is clear enough, if not let me know.

thanks,
dK



glob()

http://www.php.net/glob

How portable is glob?
How fast is glob?  Being that it searches through the entire filesystem, 
this could potentially take a long time (like if  i have wildcards early 
in the filepath pattern and lots of matches) correct?  If my file 
variations (wildcards) are just at the end of of the filepaths and i 
don't have more than 1000 files in the directory then will I most likely 
be 'alright' with glob (in terms of time)?  I have probably spent more 
time now 'considering' the time implications of glob, than glob actually 
would consume when operating...


Thanks for the quick response/solutions.
dK


[PHP] Re: file_exists and wildcard/regex

2008-12-09 Thread Maciek Sokolewicz

Daniel Kolbo wrote:
What is the preferred method with php to test and see if a file 
[pattern] exists?


For example, i only need to search in one directory, that may have any 
number of files named such as afile1.txt, afile2.txt, afile3.txt,   
And also, bfile1.txt, bfile2.txt, bfile3.txt, ...
I want to see if any such file 'family' exists.  That is, i want to see 
if there is any file named bfile[1-9][0-9]+.txt.  I don't care which 
bfile number exists, i just want to know if any bfile exists.


I hope this is clear enough, if not let me know.

thanks,
dK



glob()

http://www.php.net/glob

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



[PHP] Re: file_Exists() and case

2008-11-28 Thread Lupus Michaelis

Stan a écrit :

The script is running on an UBUNTU v8.04 LAMP server.  Case is supposed to
matter, isn't it?


  With a POSIX filesystem only. If you store you're pictures in a fat 
or ntfs filesystem, case sensitive will not matter. BTW, extension 
concept doesn't exists in POSIX filesystems, because it is unsafe.


--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

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



Re: [PHP] Re: file_Exists() and case

2008-11-24 Thread Bastien Koert
On Mon, Nov 24, 2008 at 10:02 AM, Stut <[EMAIL PROTECTED]> wrote:

> On 24 Nov 2008, at 14:41, Stan wrote:
>
>> Shouting is something that happens when people are actually speaking and
>> listening.  In a medium where there is no other way to emphasize salient
>> points in a message, capitalization is all that works.  I'm sorry it
>> offended your sensabilities.
>>
>
> It's actually well-established that capital letters indicate shouting. To
> emphasise words or phrases you should surround them with _ or *. The is also
> common practice.
>
>
>  realpath() fails, just like file_exists() fails, to report the file as
>> non-existant.
>>
>> echo "realpath(\$basePicture) returns '" . realpath($basePicture) .
>> "'\n";
>> echo "when \$basePicture is '" . $basePicture . "'\n";
>> ---
>> generates
>> ---
>> realpath($basePicture) returns '/Stan-and-Jeanne.com/pictures/2008 west
>> coast trip/2008-06-10 first week at Chris'/DSC_0011.jpg'
>> when $basePicture is '../pictures/2008 west coast trip/2008-06-10 first
>> week
>> at Chris'/DSC_0011.jpg'
>> ---
>> but ls DSC_0011.* in ../pictures/2008 west coast trip/2008-06-10 first
>> week
>> at Chris' returns only
>> ---
>> DSC_0011.JPG
>> ---
>> and
>> ---
>> try {$image = new IMagick($basePicture);
>> } catch (Exception $e) {
>>   echo 'Caught exception: ',  $e->getMessage(), "\n";
>> }
>> ---
>> results in
>> ---
>> Caught exception: unable to open image `/Stan-and-Jeanne.com/pictures/2008
>> west coast trip/2008-06-10 first week at Chris'/DSC_0011.jpg': No such
>> file
>> or directory
>> ---
>> so ... the following takes care of the extension problem in a very time
>> expensive way
>> ---
>> try
>> {
>> $image = new IMagick($basePicture);
>> }
>> catch (Exception $e)
>> {
>> $basePicture =
>>  substr($basePicture, 0, strrpos($basePicture, ".")) .
>>  "." .
>>  strtoupper(substr($basePicture, strrpos($basePicture, ".") + 1));
>> }
>> unset($image);
>> ---
>> I don't actually consider this solved and I'll return to it after
>> everything
>> else at least works.
>>
>> Now I can proceed to my next problem.
>>
>
> You never answered one of my questions. Where are you getting $basePicture
> from? Why does it differ in case from the actual file on disk. If you ask me
> you'd be better off trying to resolve this problem further upstream at the
> point where the case gets changed but your workflow doesn't appear to notice
> it.
>
> -Stut
>
> --
> http://stut.net/
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
why not just create a small script that will move the files into the correct
folder from a temp storage spot and rename them to lowercase, then you are
always dealing with the same case and it should make things easier for you.

-- 

Bastien

Cat, the other other white meat


Re: [PHP] Re: file_Exists() and case

2008-11-24 Thread Stut

On 24 Nov 2008, at 14:41, Stan wrote:
Shouting is something that happens when people are actually speaking  
and
listening.  In a medium where there is no other way to emphasize  
salient

points in a message, capitalization is all that works.  I'm sorry it
offended your sensabilities.


It's actually well-established that capital letters indicate shouting.  
To emphasise words or phrases you should surround them with _ or *.  
The is also common practice.



realpath() fails, just like file_exists() fails, to report the file as
non-existant.

echo "realpath(\$basePicture) returns '" . realpath($basePicture) .
"'\n";
echo "when \$basePicture is '" . $basePicture . "'\n";
---
generates
---
realpath($basePicture) returns '/Stan-and-Jeanne.com/pictures/2008  
west

coast trip/2008-06-10 first week at Chris'/DSC_0011.jpg'
when $basePicture is '../pictures/2008 west coast trip/2008-06-10  
first week

at Chris'/DSC_0011.jpg'
---
but ls DSC_0011.* in ../pictures/2008 west coast trip/2008-06-10  
first week

at Chris' returns only
---
DSC_0011.JPG
---
and
---
try {$image = new IMagick($basePicture);
} catch (Exception $e) {
   echo 'Caught exception: ',  $e->getMessage(), "\n";
}
---
results in
---
Caught exception: unable to open image `/Stan-and-Jeanne.com/ 
pictures/2008
west coast trip/2008-06-10 first week at Chris'/DSC_0011.jpg': No  
such file

or directory
---
so ... the following takes care of the extension problem in a very  
time

expensive way
---
try
{
$image = new IMagick($basePicture);
}
catch (Exception $e)
{
$basePicture =
 substr($basePicture, 0, strrpos($basePicture, ".")) .
 "." .
 strtoupper(substr($basePicture, strrpos($basePicture, ".") + 1));
}
unset($image);
---
I don't actually consider this solved and I'll return to it after  
everything

else at least works.

Now I can proceed to my next problem.


You never answered one of my questions. Where are you getting  
$basePicture from? Why does it differ in case from the actual file on  
disk. If you ask me you'd be better off trying to resolve this problem  
further upstream at the point where the case gets changed but your  
workflow doesn't appear to notice it.


-Stut

--
http://stut.net/


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



[PHP] Re: file_Exists() and case

2008-11-24 Thread Stan
Stut,
Shouting is something that happens when people are actually speaking and
listening.  In a medium where there is no other way to emphasize salient
points in a message, capitalization is all that works.  I'm sorry it
offended your sensabilities.

realpath() fails, just like file_exists() fails, to report the file as
non-existant.

echo "realpath(\$basePicture) returns '" . realpath($basePicture) .
"'\n";
echo "when \$basePicture is '" . $basePicture . "'\n";
---
generates
---
realpath($basePicture) returns '/Stan-and-Jeanne.com/pictures/2008 west
coast trip/2008-06-10 first week at Chris'/DSC_0011.jpg'
when $basePicture is '../pictures/2008 west coast trip/2008-06-10 first week
at Chris'/DSC_0011.jpg'
---
but ls DSC_0011.* in ../pictures/2008 west coast trip/2008-06-10 first week
at Chris' returns only
---
DSC_0011.JPG
---
and
---
try {$image = new IMagick($basePicture);
} catch (Exception $e) {
echo 'Caught exception: ',  $e->getMessage(), "\n";
}
---
results in
---
Caught exception: unable to open image `/Stan-and-Jeanne.com/pictures/2008
west coast trip/2008-06-10 first week at Chris'/DSC_0011.jpg': No such file
or directory
---
so ... the following takes care of the extension problem in a very time
expensive way
---
try
 {
 $image = new IMagick($basePicture);
 }
catch (Exception $e)
 {
 $basePicture =
  substr($basePicture, 0, strrpos($basePicture, ".")) .
  "." .
  strtoupper(substr($basePicture, strrpos($basePicture, ".") + 1));
 }
unset($image);
---
I don't actually consider this solved and I'll return to it after everything
else at least works.

Now I can proceed to my next problem.

Thanks to all,
Stan



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



Re: [PHP] Re: file_Exists() and case

2008-11-23 Thread Stut

On 23 Nov 2008, at 19:12, Stan wrote:
This thread began because file_exists() WILL NOT tell that a file  
exists FOR

SURE and FOR CERTAIN if the file you check for happens to be named
whatever.jpg and whatever.JPG exists.  I know this because IMagick  
then

chokes on whatever.jpg because it DOESN't exist.


Please don't shout at me, it won't encourage me to help you further. I  
apologise for misunderstanding, I missed the start of this thread.


The realpath function may be the answer to your problem but I don't  
have time to test it at the moment.


-Stut

--
http://stut.net/

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



Re: [PHP] Re: file_Exists() and case

2008-11-23 Thread Nathan Rixham

Stan wrote:

This thread began because file_exists() WILL NOT tell that a file exists FOR
SURE and FOR CERTAIN if the file you check for happens to be named
whatever.jpg and whatever.JPG exists.  I know this because IMagick then
chokes on whatever.jpg because it DOESN't exist.




a: you really need some manners
b: knock up you're own solution, will take 5 minutes tops;*

*http://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

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



Re: [PHP] Re: file_Exists() and case

2008-11-23 Thread Ashley Sheridan
On Sun, 2008-11-23 at 13:12 -0600, Stan wrote:
> This thread began because file_exists() WILL NOT tell that a file exists FOR
> SURE and FOR CERTAIN if the file you check for happens to be named
> whatever.jpg and whatever.JPG exists.  I know this because IMagick then
> chokes on whatever.jpg because it DOESN't exist.
> 
> 
> 
If you look at the manual for file_exists, you'll note that someone has
created a function that will check if a file exists, and make sure that
it is the correct case as well.


Ash
www.ashleysheridan.co.uk


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



[PHP] Re: file_Exists() and case

2008-11-23 Thread Stan
I do NOT want to create an empty file!

"Nathan Rixham" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Stan wrote:
> > How can I do that, please?  Do what?  Detect, programmatically, FOR SURE
and
> > FOR CERTAIN, that a specific file exists.
>
> http://uk2.php.net/touch



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



Re: [PHP] Re: file_Exists() and case

2008-11-23 Thread Stan
This thread began because file_exists() WILL NOT tell that a file exists FOR
SURE and FOR CERTAIN if the file you check for happens to be named
whatever.jpg and whatever.JPG exists.  I know this because IMagick then
chokes on whatever.jpg because it DOESN't exist.



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



[PHP] Re: file_Exists() and case

2008-11-23 Thread Nathan Rixham

Stan wrote:

How can I do that, please?  Do what?  Detect, programmatically, FOR SURE and
FOR CERTAIN, that a specific file exists.


http://uk2.php.net/touch

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



Re: [PHP] Re: file_Exists() and case

2008-11-23 Thread Stut

On 23 Nov 2008, at 18:53, Stan wrote:
Let me attack this in a different way.  This started because my  
camera names
files whatever.JPG and my thumbnail generator generates thumbnail  
files
whatever.jpg.  Given my workstation (upon which I edit code and run  
a web
browser) is W2K and my web server is APACHE2 on UBUNTU, I sometimes  
have to
run out back and scream to maintain my sanity.  I do not want  
whoever (my
wife, my kids, maybe even my grandkids) to have to manually change  
either

picture file extensions or generated thumbnail extensions on a mass of
pictures they're trying to add to our web site ... over the Internet  
in some

cases.

I was attempting to avoid the overhead of generating thumbnails on  
the fly
as I construct a page of thumbnails related to a specific event or  
subject
because I don't know how many thumbnails may be rendered.  The  
subject on

which I encountered this problem (for the second time this week) has
something in the order of 250 pictures (in several different  
directories).


What I'd really like to be able to do is to detect,  
programmatically, FOR
SURE and FOR CERTAIN, that a specific file exists BEFORE I generate  
the
anchor tag that contains the thumbnail ... given that every image  
file has a
thumbnail file in a different directory than the image file.  I need  
to try
the file identifier from which the thumbnail file identifier was  
derived
and, that failing, try changing the extension.  If I can't find it I  
don't

want to put up the thumbnail.

How can I do that, please?  Do what?  Detect, programmatically, FOR  
SURE and

FOR CERTAIN, that a specific file exists.


I don't see the problem. For a start file_exists will do exactly what  
you're asking for. It will tell you "programatically, FOR SURE and FOR  
CERTAIN, that a specific file exists". That's what it does.


I don't understand why you don't generate the thumbnails to have  
*exactly* the same filename as the actual image. And if you really  
have to give it a different name, or different case, surely you know  
the rules around how that works so you can build that logic in when  
checking for the existence of a file.


Or maybe I'm missing something.

-Stut

--
http://stut.net/

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



[PHP] Re: file_Exists() and case

2008-11-23 Thread Stan
Let me attack this in a different way.  This started because my camera names
files whatever.JPG and my thumbnail generator generates thumbnail files
whatever.jpg.  Given my workstation (upon which I edit code and run a web
browser) is W2K and my web server is APACHE2 on UBUNTU, I sometimes have to
run out back and scream to maintain my sanity.  I do not want whoever (my
wife, my kids, maybe even my grandkids) to have to manually change either
picture file extensions or generated thumbnail extensions on a mass of
pictures they're trying to add to our web site ... over the Internet in some
cases.

I was attempting to avoid the overhead of generating thumbnails on the fly
as I construct a page of thumbnails related to a specific event or subject
because I don't know how many thumbnails may be rendered.  The subject on
which I encountered this problem (for the second time this week) has
something in the order of 250 pictures (in several different directories).

What I'd really like to be able to do is to detect, programmatically, FOR
SURE and FOR CERTAIN, that a specific file exists BEFORE I generate the
anchor tag that contains the thumbnail ... given that every image file has a
thumbnail file in a different directory than the image file.  I need to try
the file identifier from which the thumbnail file identifier was derived
and, that failing, try changing the extension.  If I can't find it I don't
want to put up the thumbnail.

How can I do that, please?  Do what?  Detect, programmatically, FOR SURE and
FOR CERTAIN, that a specific file exists.

Thanks,



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



Re: [PHP] Re: file_exists

2007-11-15 Thread William Betts
It could present a problem depending on how the permissions are setup
on the shared hosting and if open_base is in effect.
If they can get the /etc/shadow file from a php being ran by apache
then you have an issue, because apache would be
running as root. Take the below example.

include('templates/".$_GET['page'].".php);

Even if you had the ability to include remote files turned on you
wouldn't be able to pull one. What you can do is pull anything
the webserver is allowed to view (ie /etc/passwd). While that doesn't
contain any passwords it lets people know valid system
logins. You can get the contents to dump by using

www.somehost.com/index.php?page=../../../../../../../../../etc/passwd%00

The %00 is what you call a null terminator. This will drop anything
that's add after it.  I hope this helps.

William Betts
On Nov 15, 2007 4:03 PM, Instruct ICC <[EMAIL PROTECTED]> wrote:
>
> > > I think file_exists returns false for remote files ;)
> >
> > Even if it did (it doesn't:
> > http://uk3.php.net/manual/en/wrappers.ftp.php), I'd still rather not let
> > someone steal my /etc/passwd or /etc/shadow etc. files.
> >
> > As I said before. Some form of regexp or similar restriction is 100%
> > necessary before trusting untrustworthy data.
> >
> > Col
>
> 1 test I did confirmed the "false" for the remote files.
>
> How about that shared host hack attempt?  Does that present a problem for 
> shared hosts?
>
> This should be my last post to this list from hotmail.  Hopefully I'll see 
> you all nicely threaded with gmail.  That's where I keep my other lists 
> anyway.
>
>
> _
> Help yourself to FREE treats served up daily at the Messenger Café. Stop by 
> today.
> http://www.cafemessenger.com/info/info_sweetstuff2.html?ocid=TXT_TAGLM_OctWLtagline

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



RE: [PHP] Re: file_exists

2007-11-15 Thread Instruct ICC

> > I think file_exists returns false for remote files ;)
> 
> Even if it did (it doesn't:
> http://uk3.php.net/manual/en/wrappers.ftp.php), I'd still rather not let
> someone steal my /etc/passwd or /etc/shadow etc. files.
> 
> As I said before. Some form of regexp or similar restriction is 100%
> necessary before trusting untrustworthy data.
> 
> Col

1 test I did confirmed the "false" for the remote files.

How about that shared host hack attempt?  Does that present a problem for 
shared hosts?

This should be my last post to this list from hotmail.  Hopefully I'll see you 
all nicely threaded with gmail.  That's where I keep my other lists anyway.

_
Help yourself to FREE treats served up daily at the Messenger Café. Stop by 
today.
http://www.cafemessenger.com/info/info_sweetstuff2.html?ocid=TXT_TAGLM_OctWLtagline

[PHP] Re: file_exists

2007-11-15 Thread Colin Guthrie
Casey wrote:
> I think file_exists returns false for remote files ;)

Even if it did (it doesn't:
http://uk3.php.net/manual/en/wrappers.ftp.php), I'd still rather not let
someone steal my /etc/passwd or /etc/shadow etc. files.

As I said before. Some form of regexp or similar restriction is 100%
necessary before trusting untrustworthy data.

Col

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



Re: [PHP] Re: file_exists

2007-11-15 Thread Casey

I think file_exists returns false for remote files ;)



On Nov 15, 2007, at 2:33 AM, Colin Guthrie <[EMAIL PROTECTED]> wrote:


Instruct ICC wrote:




Date: Thu, 15 Nov 2007 00:20:52 +
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
CC: php-general@lists.php.net
Subject: Re: [PHP] file_exists

Philip Thompson wrote:
I've run into similar problems where I *thought* I was looking in  
the

correct location... but I wasn't. Take this for example


$page = $_GET['page'];

if (file_exists ("$page.php")) {
include ("$page.php");
}
?>
I really hope this is not a piece of production code. If it is  
then you
might want to think very hard about what it's doing. If you still  
can't

see a problem let me know!



Called like this?

index.php?page=http://evil-hacker-site.com/evil-payload.php

And the browser will probably url_encode for me if needed.


Yup very dangerous.

Obviously PHP can be configured ot not include/require remote URIs,  
but

as a defensive programmer you should at very least ensure your
$_GET['page'] var conformes to a validation regexp or something...

Col

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



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



[PHP] Re: file_exists

2007-11-15 Thread Colin Guthrie
Instruct ICC wrote:
> 
> 
>> Date: Thu, 15 Nov 2007 00:20:52 +
>> From: [EMAIL PROTECTED]
>> To: [EMAIL PROTECTED]
>> CC: php-general@lists.php.net
>> Subject: Re: [PHP] file_exists
>>
>> Philip Thompson wrote:
>>> I've run into similar problems where I *thought* I was looking in the
>>> correct location... but I wasn't. Take this for example
>>>
 $page = $_GET['page'];
>>> if (file_exists ("$page.php")) {
>>> include ("$page.php");
>>> }
>>> ?>
>> I really hope this is not a piece of production code. If it is then you
>> might want to think very hard about what it's doing. If you still can't
>> see a problem let me know!
>>
> 
> Called like this?
> 
> index.php?page=http://evil-hacker-site.com/evil-payload.php
> 
> And the browser will probably url_encode for me if needed.

Yup very dangerous.

Obviously PHP can be configured ot not include/require remote URIs, but
as a defensive programmer you should at very least ensure your
$_GET['page'] var conformes to a validation regexp or something...

Col

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



Re: [PHP] Re: file_exists()

2005-10-22 Thread Jonny Bergström
On 10/23/05, Oliver Grätz <[EMAIL PROTECTED]> wrote:
>
> I believe that the problem is not Windows being unable to look fpr unicode
> files but PHP being unable to put th unicode string correctly in the command
> line you are trying to execute. Check this by doing "exec('echo 
> >test.txt'.$path);" and checking if the unicode arrives in the text file. If 
> not,
> perhaps the multibyte-extension might help out.
>
>
Yes PHP won't do this either. Unfortunately the "DOS" box in Windows doesn't
allow entering kanji either, but running a normal batch file with the same
echo line does indeed work, test.txt containing the correct characters as
entered into the .bat file.


Re: [PHP] Re: file_exists()

2005-10-22 Thread Richard Lynch
On Sat, October 22, 2005 7:12 pm, Jonny Bergström wrote:
> Good idea yes. But apparantly Windows couldn't do it either. :-(
>
> function file_exists_windows($path) {
> exec('dir ' . $path, $output, $return_status);
> return $return_status == 0 ? true : false; // Windows dir will return
> 0 when
> something was found
> }

First, I don't think $return_status is what you think it is.

$return_status is FALSE if your command is not syntactically valid.

It will be TRUE if your command is syntactically valid, but you'll
need to LOOK at $output to see if the file is listed or not.

> It works with "normal" ascii file names, but other than that it's a
> no.
> Makes you wonder what the problem is here, maybe exec() not supporting
> unicode either.

If the filename is funky, you are going to have to do whatever you
would do in a DOS prompt to escape it, munge, or otherwise convert it
to whatever that version of Windows uses.

Inlucding 8.3 on ancient Windows, if PHP runs on that junk.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] Re: file_exists()

2005-10-22 Thread Jonny Bergström
Good idea yes. But apparantly Windows couldn't do it either. :-(

function file_exists_windows($path) {
exec('dir ' . $path, $output, $return_status);
return $return_status == 0 ? true : false; // Windows dir will return 0 when
something was found
}

It works with "normal" ascii file names, but other than that it's a no.
Makes you wonder what the problem is here, maybe exec() not supporting
unicode either.


Re: [PHP] Re: file_exists()

2005-10-22 Thread Oliver Grätz
Robert Cummings schrieb:
> You could try execing a shell command to give you the answer. I don't
> know if it'll work, but worth a shot if you're in a bind.

Yep, good idea. Use the native code of the OS ofr listing the file (dir,
ls...) and parse the result.

OLLi

"Manche sagen, Computer seien besser als Menschen - aber viel Spaß
im Leben haben sie nicht." [Peter Ustinov]

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



Re: [PHP] Re: file_exists()

2005-10-22 Thread Robert Cummings
On Sat, 2005-10-22 at 19:19, Oliver Grätz wrote:
> Jonny Bergström schrieb:
> > Hi
> > 
> > file_exists('字.gif') always returns false.
> > 
> > Can anyone help me find out a way to make it work also for these kind of
> > filenames?
> > 
> Unicode filenames can't be properly handled up to now for all I know.
> Perhaps waiting for PHP6 might be your only solution.

You could try execing a shell command to give you the answer. I don't
know if it'll work, but worth a shot if you're in a bind.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



[PHP] Re: file_exists()

2005-10-22 Thread Oliver Grätz
Jonny Bergström schrieb:
> Hi
> 
> file_exists('字.gif') always returns false.
> 
> Can anyone help me find out a way to make it work also for these kind of
> filenames?
> 
Unicode filenames can't be properly handled up to now for all I know.
Perhaps waiting for PHP6 might be your only solution.

OLLi

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



[PHP] Re: file_exists() to search for *.xml file with a wild card???

2004-07-20 Thread Jason Barnett
Scott Fletcher wrote:
I would like to use the file_exists() or something similar to check for the
existance of any of the xml files regardless of what filename it use.   Like
file_exist("*.xml") for example.  Anyone know??
FletchSOD
fnmatch()
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: file_exists on Windows problem

2003-11-20 Thread Chris Williams
Thanks, that worked

"David Strencsev" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> If you're using NTFS file system... please make sure that the PHP's
temporay
> UPLOAD directory and SESSIONDATA directory are set with the correct
> permissions.
> I mean that the user IUSR_YOURCOMPUTER has write permissions in these
> directories.
>
> Hope it will help
>
> - David Strencsev

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



[PHP] Re: file_exists on Windows problem

2003-11-20 Thread David Strencsev
If you're using NTFS file system... please make sure that the PHP's temporay
UPLOAD directory and SESSIONDATA directory are set with the correct
permissions.
I mean that the user IUSR_YOURCOMPUTER has write permissions in these
directories.

Hope it will help

- David Strencsev

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



Re: [PHP] Re: file_exists on Windows problem

2003-11-19 Thread Jason Wong
On Thursday 20 November 2003 13:05, Chris Williams wrote:
> Thanks, but it make the test to move on to other things like,
> size($filename) which tells me the file does not exist.

print_r($_FILES)

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
"Little else matters than to write good code."
-- Karl Lehenbauer
*/

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



[PHP] Re: file_exists on Windows problem

2003-11-19 Thread Chris Williams
Thanks, but it make the test to move on to other things like,
size($filename) which tells me the file does not exist.

Chris
"Manuel VáZquez Acosta" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It may be an OS feature file_exists relies on...
> But you can use is_uploaded_file() function to check whether the file
exists
> or not.
>
> Manu.
>
>
> "Chris Williams" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > I'm again trying to understand differences in Apache and Windows
installs
> of
> > PHP when I try to upload a file to the server. It seems on Windows, I
> can't
> > get the file I'm uploading.
> >
> > To try to understand this I created a very simple html form that uploads
a
> > text file to the server's TEMP directory using:
> >
> > 
> >
> > The script Upload.php contains the following:
> >
> > $filename = $_FILES['datafile']['tmp_name'];
> > echo "filename: " . $filename ."";
> >
> > if (file_exists("$filename")) {
> > print "The file $filename exists";
> > } else {
> > print "The file $filename does not exist";
> > }
> >
> > echo "";
> >
> > @readfile($filename);
> >
> > echo "";
> >
> > Now the file seems to have been copied to the server because filename
> prints
> > out the path to the file and @readfile($filename) displays the content
of
> > the file. However, file_exists tells me the file does not exist. I also
> > tired getting file size but again I got an error no file exists.
> >
> > Of course this all works on Apache. What is up with this?
> >
> > Thanks
> > Chris

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



[PHP] Re: file_exists on Windows problem

2003-11-19 Thread Manuel Vázquez Acosta
It may be an OS feature file_exists relies on...
But you can use is_uploaded_file() function to check whether the file exists
or not.

Manu.


"Chris Williams" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm again trying to understand differences in Apache and Windows installs
of
> PHP when I try to upload a file to the server. It seems on Windows, I
can't
> get the file I'm uploading.
>
> To try to understand this I created a very simple html form that uploads a
> text file to the server's TEMP directory using:
>
> 
>
> The script Upload.php contains the following:
>
> $filename = $_FILES['datafile']['tmp_name'];
> echo "filename: " . $filename ."";
>
> if (file_exists("$filename")) {
> print "The file $filename exists";
> } else {
> print "The file $filename does not exist";
> }
>
> echo "";
>
> @readfile($filename);
>
> echo "";
>
> Now the file seems to have been copied to the server because filename
prints
> out the path to the file and @readfile($filename) displays the content of
> the file. However, file_exists tells me the file does not exist. I also
> tired getting file size but again I got an error no file exists.
>
> Of course this all works on Apache. What is up with this?
>
> Thanks
> Chris

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



[PHP] Re: file_exists for URLs

2002-10-14 Thread Owen Prime

Have a look at the fopen() function in the FileSystem Function section of 
the Docs. fopen() can open a file over http:// and I imagine it returns 
FALSE if it cant open it. If it doesn't return false, you could analyse the 
headers in $http_response_header.

Hope this helps.

Cheers,

Owen Prime
http://www.noggin.com.au


Adrian Slusarczyk wrote:

> Hi,
> 
> I'm kinda new to PHP and have the following problem: In a function, I want
> to verify whether a
> file exists before I go on, and if it doesn´t, return false and stop right
> there. So I tried
> 
> if(!file_exists($my_file)) {
> return false;
> exit;
> }
> 
> But since $my_file is a URL, it doesn´t work. Does anybody know how to do
> this so it works with URLs, i.e. w/o using file_exists() ?
> 
> Thx!



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




[PHP] Re: file_exists

2002-05-06 Thread Austin Marshall

Craig Westerman wrote:
> What am I doing wrong? I get parse error between first echo statement and
> else.
> 
> Thanks
> 
> Craig ><>
> [EMAIL PROTECTED]
> 
> 
>  $fn = "image.gif";
> if (!file_exists($fn)) {
> echo "";
> else
> echo "";
> }
> ?>
> 

You've got your semicolons in the wrong spots. Try:

";
}
else
{
echo "";
}

?>




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




[PHP] Re: file_exists problems

2001-12-01 Thread Fred

file_exists takes a string argument.
/images/$filename is not a string.
try "images/" . $filename instead.

Fred

Prolog <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I had a script that was running beautiful that simply called up a database
> and displayed the results in tables.  I went to add images to this script
> and all hell broke loose.  This is the portion of the script that I added:
>
>
> --
>
> file://filename is the item number + t.jpg -- t shorthand for thumbnail
>
>   $itemnumber = "$myrow[item_number]";
>   $filename = "$itemnumber t.jpg";
>
> echo "";
>
> file://if the file exists then print it.  Otherwise print a generic image
saying
> it doesn't exist.
>
>  if(file_exists(/images/$filename))
>  {
>   readfile(/images/$filename);
>  }
>  else
>  {
>   readfile(images/npat.jpg);
>  }
>
> -
>
> Is there anything I need to know about "file_exists" that I'm not doing.
> for some reason when this code is added it gives me an error on the line
> after the close of the else statement.  That line was perfectly fine
before
> the addition.  Please help.
>
> -Jordan
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]