Jump to content

XAMPP thumbnails won't delete


Martijn Geerts
 Share

Recommended Posts

Ryan,

looks like you have some hard-coded assumptions of unix path separators in the codebase that might better be swapped for the DS constant. Take a look at _copyFiles() in PagefilesManager.php for one example (there might be more)...

protected function _copyFiles($fromPath, $toPath) {
 if(!is_dir($toPath)) return 0;
 $numCopied = 0;
 $fromPath = rtrim($fromPath, '/') . '/';
 $toPath = rtrim($toPath, '/') . '/';

 foreach(new DirectoryIterator($fromPath) as $file) {
  if($file->isDot()) continue;
  if($file->isDir()) {
   $newPath = $toPath . $file->getFilename() . '/';
   $this->_createPath($newPath);
   $numCopied += $this->_copyFiles($file->getPathname(), $newPath);
   continue;
  }
  if($file->isFile()) {
   if(copy($file->getPathname(), $toPath . $file->getFilename())) $numCopied++;
  }
 }
 return $numCopied;

Where you are doing trims + replaces with forward slashes (unix-specific) rather than the OS-neutral DS. Check out this post of mine from waaaayyyy back in my Textpattern days for more background.

I'm not suggesting this is the exact source of the problem being reported in this thread but I think it does represent a code portability issue for PW.

Link to comment
Share on other sites

Thanks Steve. We normalize to forward '/' slashes internally, and I normalize them as soon as anything comes from the OS (see /wire/core/Paths.php). I don't think that function is involved in this particular case, but like you pointed out, that function does assume it's dealing with paths in an expected format that have already been normalized. The setFilename() function also assumes it's dealing with filenames in an expected format, so that extra slash must be finding its way in there before the function call. What I'm looking for is any native PHP that would return a path, like a DirectoryIterator loop where maybe I'm doing something like in that function you pointed out -- a trim($dir, '/') rather than a trim($dir, DIRECTORY_SEPARATOR). So far I haven't found it, but the hunt is on. :)

  • Like 1
Link to comment
Share on other sites

Might have just found it: the getVariations() function in /wire/core/Pageimage.php calls setFilename() with a non-normalized path from DirectoryIterator. Though still not clear why the $file->getPathname() from DirectoryIterator would be returning a file in the format with both types of slashes (/path/to/file\file.jpg). But that bit of code in Pageimage.php is a problem either way, as it doesn't consider the slashes and it needs to. Luckily an easy fix.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
Tried replacing Pagefile.php, and it works for me

This was actually fixed in the current version's source code about 10 days ago, so it's better just to grab the latest version of ProcessWire rather than replacing Pagefile.php.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...