is_writable example

<?php _e( 'Documentation:' ); ?></label> <?php echo $docs_select; ?> <input disabled id="docs-lookup" type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&amp;locale=<?php echo urlencode( get_user_locale() ); ?>&amp;version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&amp;redirect=true'); }" /> </div> <?php endif; ?> <div> <div class="editor-notices"> <?php if ( is_child_theme() && $theme->get_stylesheet() === get_template() ) : ?> <div class="notice notice-warning inline"> <p> <?php if ( is_writable( $file ) ) : ?> <strong><?php _e( 'Caution:' ); ?></strong> <?php endif; ?> <?php _e( 'This is a file in your current parent theme.' ); ?> </p> </div> <?php endif; ?> </div> <?php if ( is_writable( $file ) ) : ?> <p class="submit"> <?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?> <span class="spinner"></span> </p>
class Utils
{
    /** * @param string $file * * @return bool */
    public static function check($file)
    {
        if (file_exists($file)) {
            if (!is_writable($file)) {
                return $file;
            }

            return true;
        }

        return self::check(\dirname($file));
    }

    /** * @param string $xmlPath * * @return array */
private readonly bool $clusterMode,
        private readonly MessageBusInterface $messageBus
    ) {
    }

    public function clear(): void
    {
        foreach ($this->adapters as $adapter) {
            $adapter->clear();
        }

        if (!is_writable($this->cacheDir)) {
            throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $this->cacheDir));
        }

        $this->cacheClearer->clear($this->cacheDir);

        if ($this->clusterMode) {
            // In cluster mode we can't delete caches on the filesystem             // because this only runs on one node in the cluster             return;
        }

        
$this->name = "$this->location/$this->filename.$this->extension";
    }

    /** * Save data to the cache * * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property * @return bool Successfulness */
    public function save($data)
    {
        if (file_exists($this->name) && is_writable($this->name) || file_exists($this->location) && is_writable($this->location))
        {
            if ($data instanceof SimplePie)
            {
                $data = $data->data;
            }

            $data = serialize($data);
            return (bool) file_put_contents($this->name, $data);
        }
        return false;
    }

    
if ($success) {
        return TRUE;
      }
      // If the operation failed, check again if the directory was created       // by another process/server, only report a failure if not. In this case       // we still need to ensure the directory is writable.       if (!is_dir($directory)) {
        return FALSE;
      }
    }

    $writable = is_writable($directory);
    if (!$writable && ($options & static::MODIFY_PERMISSIONS)) {
      return $this->chmod($directory);
    }

    return $writable;
  }

  /** * {@inheritdoc} */
  public function getDestinationFilename($destination$replace) {
    

    /** * Extracts the provided zip file to the provided destination * * @param ZipArchive $archive * @param string $destination * * @throws Exception */
    public function extract($archive$destination)
    {
        if (!is_writable($destination)) {
            throw new Exception(sprintf('Destination directory "%s" is not writable', $destination));
        }

        $this->validatePluginZip($archive);

        $archive->extractTo($destination);

        $this->clearOpcodeCache();
    }

    /** * Iterates all files of the provided zip archive * path and validates the plugin namespace, directory traversal * and multiple plugin directories. * * @throws Exception */
// No files to delete.         if ( ! $files ) {
            return true;
        }

        // Check all files are writable before attempting to clear the destination.         $unwritable_files = array();

        // Check writability.         foreach ( $files as $file ) {
            if ( ! $wp_filesystem->is_writable( $file ) ) {
                // Attempt to alter permissions to allow writes and try again.                 $wp_filesystem->chmod( $file, FS_CHMOD_FILE );
                if ( ! $wp_filesystem->is_writable( $file ) ) {
                    $unwritable_files[] = $file;
                }
            }
        }

        if ( ! empty( $unwritable_files ) ) {
            return new WP_Error( 'files_not_writable', $this->strings['files_not_writable']implode( ', ', $unwritable_files ) );
        }

        
if (!$this->_verifyPath($id)) {
            Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
        }
        $fileName = basename($id);
        if ($fileName === '') {
            $fileName = $this->_options['index_filename'];
        }
        $pathName  = $this->_options['public_dir'] . dirname($id);
        $file      = $pathName . '/' . $fileName . $this->_options['file_extension'];
        $directory = $pathName . '/' . $fileName;
        if (file_exists($directory)) {
            if (!is_writable($directory)) {
                return false;
            }
            if (is_dir($directory)) {
                foreach (new DirectoryIterator($directory) as $file) {
                    if (true === $file->isFile()) {
                        if (false === unlink($file->getPathName())) {
                            return false;
                        }
                    }
                }
            }
            

    public function warmUp(string $cacheDir): array
    {
        $files = [];
        foreach ($this->registry->getManagers() as $em) {
            // we need the directory no matter the proxy cache generation strategy             if (!is_dir($proxyCacheDir = $em->getConfiguration()->getProxyDir())) {
                if (false === @mkdir($proxyCacheDir, 0777, true) && !is_dir($proxyCacheDir)) {
                    throw new \RuntimeException(sprintf('Unable to create the Doctrine Proxy directory "%s".', $proxyCacheDir));
                }
            } elseif (!is_writable($proxyCacheDir)) {
                throw new \RuntimeException(sprintf('The Doctrine Proxy directory "%s" is not writeable for the current system user.', $proxyCacheDir));
            }

            // if proxies are autogenerated we don't need to generate them in the cache warmer             if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
                continue;
            }

            $classes = $em->getMetadataFactory()->getAllMetadata();

            $em->getProxyFactory()->generateProxyClasses($classes);

            
if ($this->inline_attachments === true) {
                            // great                         } elseif (is_int($this->inline_attachments)) {
                            if ($this->inline_attachments < $thisfile_ape_items_current['data_length']) {
                                // too big, skip                                 $this->warning('attachment at '.$thisfile_ape_items_current['offset'].' is too large to process inline ('.number_format($thisfile_ape_items_current['data_length']).' bytes)');
                                unset($thisfile_ape_items_current['data']);
                                break;
                            }
                        } elseif (is_string($this->inline_attachments)) {
                            $this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR);
                            if (!is_dir($this->inline_attachments) || !getID3::is_writable($this->inline_attachments)) {
                                // cannot write, skip                                 $this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$this->inline_attachments.'" (not writable)');
                                unset($thisfile_ape_items_current['data']);
                                break;
                            }
                        }
                        // if we get this far, must be OK                         if (is_string($this->inline_attachments)) {
                            $destination_filename = $this->inline_attachments.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$thisfile_ape_items_current['data_offset'];
                            if (!file_exists($destination_filename) || getID3::is_writable($destination_filename)) {
                                file_put_contents($destination_filename$thisfile_ape_items_current['data']);
                            }
case 'NONCE_KEY':
                case 'AUTH_SALT':
                case 'SECURE_AUTH_SALT':
                case 'LOGGED_IN_SALT':
                case 'NONCE_SALT':
                    $config_file[ $line_num ] = "define( '" . $constant . "'," . $padding . "'" . $secret_keys[ $key++ ] . "' );\r\n";
                    break;
            }
        }
        unset( $line );

        if ( ! is_writable( ABSPATH ) ) :
            setup_config_display_header();
            ?> <p> <?php             /* translators: %s: wp-config.php */
            printf( __( 'Unable to write to %s file.' ), '<code>wp-config.php</code>' );
            ?> </p> <p id="wp-config-description"> <?php             /* translators: %s: wp-config.php */
            
/** * @param string|null $lockPath the directory to store the lock, defaults to the system's temporary directory * * @throws LockStorageException If the lock directory doesn’t exist or is not writable */
    public function __construct(string $lockPath = null)
    {
        if (!is_dir($lockPath ??= sys_get_temp_dir())) {
            if (false === @mkdir($lockPath, 0777, true) && !is_dir($lockPath)) {
                throw new InvalidArgumentException(sprintf('The FlockStore directory "%s" does not exists and cannot be created.', $lockPath));
            }
        } elseif (!is_writable($lockPath)) {
            throw new InvalidArgumentException(sprintf('The FlockStore directory "%s" is not writable.', $lockPath));
        }

        $this->lockPath = $lockPath;
    }

    /** * @return void */
    public function save(Key $key)
    {
        
// If the start and end file is exactly the same, there is nothing to do.     if ($this->isLocationUnchanged($source$destination)) {
      return $destination;
    }

    // Check if a writable directory exists, and if not try to create it.     $dir = $this->getDirectory($destination);
    // If the directory exists and is writable, avoid     // \Drupal\Core\File\FileSystemInterface::prepareDirectory() call and write     // the file to destination.     if (!is_dir($dir) || !is_writable($dir)) {
      if (!$this->fileSystem->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
        throw new MigrateException("Could not create or write to directory '$dir'");
      }
    }

    $final_destination = $this->writeFile($source$destination$this->configuration['file_exists']);
    if ($final_destination) {
      return $final_destination;
    }
    throw new MigrateException("File $source could not be copied to $destination");
  }

  
/** * Checks a requirement * * @param string $name * * @return bool */
    private function checkExits($name)
    {
        $name = $this->basePath . $name;

        return file_exists($name) && is_readable($name) && is_writable($name);
    }
}

    public function setAttributeDir($dir)
    {
        if (!is_dir($dir)) {
            if (@mkdir($dir, 0777, true) === false && !is_dir($dir)) {
                throw new RuntimeException(sprintf("Unable to create the doctrine attribute directory (%s)\n", $dir));
            }
        } elseif (!is_writable($dir)) {
            throw new RuntimeException(sprintf("Unable to write in the doctrine attribute directory (%s)\n", $dir));
        }

        $dir = rtrim((string) realpath($dir), '\\/') . DIRECTORY_SEPARATOR;

        $this->attributeDir = $dir;

        return $this;
    }

    /** * @return string */
Home | Imprint | This part of the site doesn't use cookies.