Jump to content

is_file file_exists filesize problems on cifs mount


crazyzed

Recommended Posts

From my old gentoo server I run the following code with success. "/mnt/images" is a cifs mount!

<?php
$source = '/mnt/images/1001.jpg';
$target = '/tmp/1001.jpg';

if ( file_exists($source) )
echo "file_exists: TRUE<br/>";
else
echo "file_exists: FALSE<br/>";

if ( is_file($source) )
echo "is_file: TRUE<br/>";
else
echo "is_file: FALSE<br/>";

if ( copy($source, $target) )
echo "copy: TRUE<br/>";
else
echo "copy: FALSE<br/>";

echo "filesize source: ".filesize($source)."<br/>";
echo "filesize target: ".filesize($target)."<br/>";
?>

The output is

file_exists: TRUE

is_file: TRUE

copy: TRUE

filesize source: 4715

filesize target: 4715

When I try this on my newly installed CentOS machine I get

file_exists: FALSE

is_file: FALSE

 

Warning: copy(/mnt/images/1001.jpg) [function.copy]: failed to open stream: Permission denied in /var/www/html/filetest.php on line 16

copy: FALSE

 

Warning: filesize() [function.filesize]: stat failed for /mnt/images/1001.jpg in /var/www/html/filetest.php on line 21

filesize source:

 

Warning: filesize() [function.filesize]: stat failed for /tmp/1001.jpg in /var/www/html/filetest.php on line 22

filesize target:

Every function fails. Then I found that when I disable SELinux with "echo 0 > /selinux/enforce" file_exists() and copy() works.

file_exists: TRUE

is_file: FALSE

copy: TRUE

 

Warning: filesize() [function.filesize]: stat failed for /mnt/images/1001.jpg in /var/www/html/filetest.php on line 21

filesize source:

filesize target: 4715

But is_file() and filesize() still doesn't work. They all work when I run them on local files so it is somewhat related to the cifs mount.

What could be the problem here?

Link to comment
Share on other sites

File permissions are the same except for the SELinux addition on CentOS, but as I said I have it disabled right now.

-rwxr-xr-x. 1 root root  4715 Dec  2  2009 1001.jpg

And /etc/fstab is the same on both servers

//192.168.0.2/tmp /mnt/images cifs noauto 0 0

I find it really odd that file_exists() works but is_file() doesn't.

 

But in this case it's really the filesize() function that I need working!

Link to comment
Share on other sites

I find it really odd that file_exists() works but is_file() doesn't.

 

Yeah, that is strange, if it were the other way around I wouldn't be surprised since the manual for file_exists says

 

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.

 

Anyway, I'm still going with permissions until all possibilities are ruled out... Your mount is set to owner & group root, try changing one file to whatever user you apache server is running under. Check httpd.conf because some distributions default to www:www, and others to nobody:default.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.