crazyzed Posted September 23, 2011 Share Posted September 23, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/247723-is_file-file_exists-filesize-problems-on-cifs-mount/ Share on other sites More sharing options...
WebStyles Posted September 23, 2011 Share Posted September 23, 2011 I'm guessing file permissions... Quote Link to comment https://forums.phpfreaks.com/topic/247723-is_file-file_exists-filesize-problems-on-cifs-mount/#findComment-1272179 Share on other sites More sharing options...
requinix Posted September 23, 2011 Share Posted September 23, 2011 How do the mount options compare between the two servers? Quote Link to comment https://forums.phpfreaks.com/topic/247723-is_file-file_exists-filesize-problems-on-cifs-mount/#findComment-1272180 Share on other sites More sharing options...
crazyzed Posted September 24, 2011 Author Share Posted September 24, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/247723-is_file-file_exists-filesize-problems-on-cifs-mount/#findComment-1272283 Share on other sites More sharing options...
WebStyles Posted September 24, 2011 Share Posted September 24, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247723-is_file-file_exists-filesize-problems-on-cifs-mount/#findComment-1272416 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.