Reply to Re: is_writable() is lying to me

Your name:

Reply:


Posted by Justin Koivisto on 11/08/59 11:31

Peter wrote:
> Very perplexing. This function creates a png image of a random string (this
> is to filter out blogging spam). It should be very straight forward.
>
>
> function createImage( $text=0 )
> {
> $img_dir = '/tmp';
>
> (snip!)
>
> $filename = "$img_dir/" . randomString(12) . '.png';
>
> if ( ! is_writable($filename) )
> echo ("Can't write to $filename<br>");
>
> ImagePNG( $image, $filename );
> ImageDestroy( $image );
>
> return array(
> 'filename' => $filename,
> 'passkey' => $text
> );
> }
>
>
> When I call this function, it prints on the webpage, e.g.
>
> Can't write to /tmp/TsP1gTUNwAOyQ.png
>
> However, that file clearly exists:
>
> $ ll /tmp/TsP1gTUNwAOyQ.png
> -rw-r--r-- www-data www-data 200 2005-11-09 /tmp/TsP1gTUNwAOyQ.png
>
> How can is_writable() be wrong?
>
>
>
> In related wierdness, I use this function like so:
>
> $retval = createImage();
> $filename = $retval['filename'];
> $passkey = $retval['passkey'];
> echo "<img src=\"$filename\" />";
>
> But the image doesn't show up in the browser. When I look at the page
> source, the statement is there and looks correct:
>
> <img src="/tmp/c2GfviA4r4b47.png" />
>
> and I can even view the image with xv and gimp, however, the image is simply
> not on the webpage.
>
> I strongly suspect that these two oddities are related, but I'm running out
> of ideas. Anyone have any suggestions?

The file isn't writable because it doesn't exist... you need to check
the directory...

<?php
if( (file_exists($filename)
&& is_writable($filename))
||
(file_exists(dirname($filename))
&& is_writable(dirname($filename)))
){
// can create or overwrite file
}else{
// cannot create or overwrite file
// directory may not exist, directory may
// now allow write permission, or the file
// exists and does not allow write permission
}
?>

--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация