<?php 
##
#	Project: PHPDISK File Storage Solution
#	This is NOT a freeware, use is subject to license terms.
#
#	Site: http://www.phpdisk.com
#
#	$Id: file.func.php 25 2011-03-04 07:36:51Z along $
#
#	Copyright (C) 2008-2011 PHPDisk Team. All Rights Reserved.
#
##

if(!defined('IN_PHPDISK')) {
	exit('[PHPDisk] Access Denied');
}

function read_file($f) { 
    if (file_exists($f)) { 
        if (PHP_VERSION >= "4.3.0") return file_get_contents($f); 
        $fp = fopen($f,"rb"); 
        $fsize = filesize($f); 
        $c = fread($fp, $fsize); 
        fclose($fp); 
        return $c; 
    } else{
		exit("<b>$f</b> does not exist!"); 
	}
} 

function write_file($f,$str,$mode = 'wb') { 
    $fp = fopen($f,$mode); 
    if (!$fp) { 
        exit("Can not open file <b>$f</b> .code:1");
    } 
	if(is_writable($f)){
		if(!fwrite($fp,$str)){
			exit("Can not write file <b>$f</b> .code:2");
		} 
	}else{
		exit("Can not write file <b>$f</b> .code:3");
	}
    fclose($fp); 
} 
function upload_file($source, $target) {
		if (function_exists('move_uploaded_file') && @move_uploaded_file($source, $target)) {
		@chmod($target, 0666);
		return $target;
	} elseif (@copy($source, $target)) {
		@chmod($target, 0666);
		return $target;
	} elseif (@is_readable($source)) {
		if ($fp = @fopen($source,'rb')) {
			@flock($fp,2);
			$filedata = @fread($fp,@filesize($source));
			@fclose($fp);
		}
		if ($fp = @fopen($target, 'wb')) {
			@flock($fp, 2);
			@fwrite($fp, $filedata);
			@fclose($fp);
			@chmod ($target, 0666);
			return $target;
		} else {
			return false;
		}
	}
}

?>