Ejemplo n.º 1
0
/**
 * Supprimer un fichier de manière sympa (flock)
 *
 * @param string $fichier
 *     Chemin du fichier
 * @param bool $lock
 *     true pour utiliser un verrou
 * @return bool|void
 *     - true si le fichier n'existe pas
 *     - false si on n'arrive pas poser le verrou
 *     - void sinon
 */
function supprimer_fichier($fichier, $lock = true)
{
    if (!@file_exists($fichier)) {
        return true;
    }
    if ($lock) {
        // verrouiller le fichier destination
        if (!($fp = spip_fopen_lock($fichier, 'a', LOCK_EX))) {
            return false;
        }
        // liberer le verrou
        spip_fclose_unlock($fp);
    }
    // supprimer
    return @unlink($fichier);
}
Ejemplo n.º 2
0
function recuperer_body($f, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '')
{
    $taille = 0;
    $result = '';
    $fp = false;
    if ($fichier) {
        include_spip("inc/acces");
        $tmpfile = "{$fichier}." . creer_uniqid() . ".tmp";
        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
        if (!$fp and file_exists($fichier)) {
            return filesize($fichier);
        }
        if (!$fp) {
            return false;
        }
        $result = 0;
        // on renvoie la taille du fichier
    }
    while (!feof($f) and $taille < $taille_max) {
        $res = fread($f, 16384);
        $taille += strlen($res);
        if ($fp) {
            fwrite($fp, $res);
            $result = $taille;
        } else {
            $result .= $res;
        }
    }
    if ($fp) {
        spip_fclose_unlock($fp);
        spip_unlink($fichier);
        @rename($tmpfile, $fichier);
        if (!file_exists($fichier)) {
            return false;
        }
    }
    return $result;
}
Ejemplo n.º 3
0
function migration_recuperer_body($f, $taille_max=1048576, $fichier='')
{
	$taille = 0;
	$result = '';
	if ($fichier){
		$fp = spip_fopen_lock($fichier, 'w',LOCK_EX);
		if (!$fp) return false;
		$result = 0; // on renvoie la taille du fichier
	}
	while (!feof($f) AND $taille<$taille_max){
		$res = fread($f, 16384);
		$taille += strlen($res);
		if ($fp){
			fwrite($fp,$res);
			$result = $taille;
		}
		else
			$result .= $res;
	}
	if ($fp)
		spip_fclose_unlock($fp);
	return $result;
}