예제 #1
0
/** NOTE: This script is used to generate the "Packages" and "Packages.gz" files that Debian-based repositories uses. It can also be used to make OPKG-repositories. */
function ipkg_parse($file)
{
    require_once "knj/os.php";
    require_once "knj/functions_knj_filesystem.php";
    require_once "knj/strings.php";
    $fileinfo = fileinfo($file);
    if (strpos($fileinfo, "gzip compressed data") !== false) {
        $format = "tar.gz";
    } else {
        $format = "debian";
    }
    $old_dir = getcwd();
    $tmpdir = "./generate_packages_list_" . microtime(true);
    while (true) {
        if (file_exists($tmpdir)) {
            $tmpdir .= "1";
        } else {
            break;
        }
    }
    if (!mkdir($tmpdir)) {
        throw new exception("Could not create temp-dir: " . $tmpdir);
    }
    $finfo = pathinfo($file);
    $cmd = "cd " . knj_string_unix_safe($tmpdir) . ";";
    if ($format == "tar.gz") {
        $cmd .= "tar -zxmvf ../" . knj_string_unix_safe($fino["basename"]);
    } else {
        $cmd .= "ar -x ../" . knj_string_unix_safe($finfo["basename"]) . " control.tar.gz";
    }
    $res = knj_os::shellCMD($cmd);
    if (strlen($res["error"]) > 0) {
        throw new exception(trim($res["error"]));
    }
    $res = knj_os::shellCMD("cd " . knj_string_unix_safe($tmpdir) . "; tar -zxmvf control.tar.gz");
    if (strlen($res["error"]) > 0) {
        throw new exception(trim($res["error"]));
    }
    $res = knj_os::shellCMD("cd " . knj_string_unix_safe($tmpdir) . "; cat control");
    if (strlen($res["error"]) > 0) {
        throw new exception(trim($res["error"]));
    }
    $control = substr($res["result"], 0, -1);
    $return = array();
    foreach (explode("\n", $control) as $line) {
        if (preg_match("/^(\\S+):\\s+([\\s\\S]+)\$/", $line, $match)) {
            if (strlen(trim($match[2])) > 0) {
                $return["control"][$match[1]] = $match[2];
            }
        }
    }
    knj_os::shellCMD("cd " . knj_string_unix_safe($old_dir));
    fs_cleanDir($tmpdir, true);
    if (file_exists($tmpdir)) {
        if (!rmdir($tmpdir)) {
            throw new Exception("Could not remove tmp-dir.");
        }
    }
    return $return;
}
예제 #2
0
 /**
  * Check if the cache-file exists
  */
 public function hit($duration = 60)
 {
     $infos = fileinfo($this->file);
     if ($infos["mtime"] + $duration * 60 > time()) {
         $ret = true;
     }
     return $ret;
 }
예제 #3
0
<h1>File Info Extension Demo</h1>
Call a script, actually included in this page with a filename as parameter. The 
PHP script retrieves essential infos about the file and display them below in 
this page. 
<FORM name="ajax" method="POST" action="">
  <blockquote> 
    <p>
      <input type="text" name="filename" value="demo-fileinfo.php">
      <INPUT type="submit" value="Get Infos">
    </p>
  </blockquote>
</FORM>

<div id="zone">
</div>

	
<p>
<?php 
echo "File {$filename}<br><br>";
$x = fileinfo($filename);
print_r($x);
?>
</p>

<p>(c) 2007 <a href="http://www.anaa.eu" target="_parent">Anaa.eu</a></p>


</body>
</html>
예제 #4
0
function file_list($path, $include_files = array(), $ignore_files = array(), $setting = NULL)
{
    $result = array();
    $include_files = to_array($include_files);
    $ignore_files = to_array($ignore_files);
    //Format include_files
    foreach ($include_files as $key => $value) {
        $include_files[$key] = normalize_path($value);
    }
    //Format ignore_files
    foreach ($ignore_files as $key => $value) {
        $ignore_files[$key] = normalize_path($value);
    }
    $_setting = array('file_key' => ($setting & FILE_LIST_FILE_KEY) == FILE_LIST_FILE_KEY, 'debug_path' => ($setting & FILE_LIST_DEBUG_PATH) == FILE_LIST_DEBUG_PATH, 'file_info' => ($setting & FILE_LIST_FILE_INFO) == FILE_LIST_FILE_INFO, 'include_folder' => ($setting & FILE_LIST_INCLUDE_FOLDER) == FILE_LIST_INCLUDE_FOLDER, 'subfolder' => ($setting & FILE_LIST_SUBFOLDER) == FILE_LIST_SUBFOLDER);
    $queue = array($path);
    $pt = NULL;
    while (list($k, $path) = each($queue)) {
        //3
        ///*
        if ($handle = opendir($path)) {
            while (FALSE !== ($file = readdir($handle))) {
                //2
                if ($file == '.' || $file == '..') {
                    continue 1;
                }
                $real_path = normalize_path($path . DIRECTORY_SEPARATOR . $file);
                if (is_dir($real_path)) {
                    $_setting['include_folder'] && ($queue[] = $real_path);
                    if (!$_setting['include_folder']) {
                        continue 1;
                    }
                }
                foreach ($include_files as $key => $value) {
                    //1
                    if (!fnmatch($value, $real_path, FNM_CASEFOLD | FNM_NOESCAPE)) {
                        continue 2;
                    }
                }
                foreach ($ignore_files as $value) {
                    //1
                    if (fnmatch($value, $real_path, FNM_CASEFOLD | FNM_NOESCAPE)) {
                        continue 2;
                    }
                }
                if ($_setting['file_key']) {
                    $pt =& $result[anystring2utf8(str_replace('\\', '/', $_setting['debug_path'] ? Debug::path($real_path) : $real_path))];
                } else {
                    $pt =& $result[];
                }
                $pt = $_setting['file_info'] ? fileinfo($real_path) : $real_path;
            }
        }
        closedir($handle);
        //*/
        /*
        		$path .= DIRECTORY_SEPARATOR;
        		$list = glob($path.'{.,}*',GLOB_BRACE | GLOB_NOESCAPE );
        		foreach ($list as $real_path)
        		{
        			if ($real_path == $path.'.' || $real_path == $path.'..') continue 1;
        			$real_path = normalize_path($real_path);
        			foreach($ignore_files as $value)
        			{
        				if (fnmatch($value, $real_path, FNM_PATHNAME | FNM_CASEFOLD | FNM_NOESCAPE))
        					continue 2;
        			}
        			$result[str_replace('\\','/', $debug_path ? Debug::path($real_path) : $real_path)] = $fileinfo = fileinfo($real_path);
        			if ($fileinfo['type'] == 'dir')
        				$queue[] = $real_path;
        		}
        		//*/
    }
    ksort($result);
    //print_r($result);
    return $result;
}
예제 #5
0
파일: cmd.php 프로젝트: carriercomm/binbash
         }
         break;
     case 'cat':
         if (isset($_GET['file'])) {
             $res = cat(sanitize_input($_GET['file']));
         }
         break;
     case 'head':
         if (isset($_GET['file'])) {
             isset($_GET['lines']) and $lines = sanitize_input($_GET['lines']) or $lines = 10;
             $res = catN(sanitize_input($_GET['file']), $lines);
         }
         break;
     case 'file':
         if (isset($_GET['file'])) {
             $res = fileinfo(sanitize_input($_GET['file']));
         }
         break;
     case 'info':
         if (isset($_GET['dir'])) {
             $res = showinfo(sanitize_input($_GET['dir']));
         } else {
             $res = showinfo('.');
         }
         break;
         /*case 'grep': if (isset($_GET['dir']) and isset($_GET['expr'])) {
         			
         			$res = grep($_GET['dir'],$_GET['expr']);
         		}
         		break;*/
 }
예제 #6
0
 /**
  * Automatically sets the ETag header according to the checksum of the file.
  */
 public function setAutoEtag()
 {
     $this->setEtag(md5(serialize(fileinfo($this->file->getPathname()))));
     return $this;
 }
예제 #7
0
/**
 * Function for uploading of images via the upload form
 * 
 * @class nggAdmin
 * @return void
 */
function upload_images($galleryID, $image, $desc, $title)
{
    global $wpdb;
    $gallery = $wpdb->prefix . "spf_gallery";
    $pictures = $wpdb->prefix . "spf_pictures";
    if ($galleryID == 0) {
        show_error(__('No gallery selected !', 'nggallery'));
        return;
    }
    $gid = $galleryID;
    $query = "SELECT * FROM " . $gallery . " WHERE gid='" . $gid . "'";
    $results = mysql_query($query);
    $count = mysql_num_rows($results);
    while ($data = mysql_fetch_array($results)) {
        //$id = $data['gid'];
        $fullpath = ABSPATH . stripslashes($data['path']);
        ///$quote = stripslashes($data['description']);
    }
    $fullpath = str_replace("\\", "/", $fullpath);
    if (empty($fullpath)) {
        nggGallery::show_error(__('Failure in database, no gallery path set !', 'nggallery'));
        return;
    }
    // read list of images
    //$dirlist = scandir($fullpath);
    $imagefiles = $image;
    // look only for uploded files
    if ($imagefiles['error'] == 0) {
        $temp_file = $imagefiles['tmp_name'];
        //clean filename and extract extension
        $filepart = fileinfo($imagefiles['name']);
        print_r($filepart);
        echo $filename = $filepart['basename'];
        // check for allowed extension and if it's an image file
        $ext = array('jpg', 'png', 'gif', 'bmp', 'jpeg');
        if (!in_array($filepart['extension'], $ext)) {
            show_error('<strong>' . $imagefiles['name'] . ' </strong>' . __('is no valid image file!', 'nggallery'));
            //continue;
        }
        // check if this filename already exist in the folder
        if (file_exists($fullpath . $filename)) {
            $txt = "File ({$filename}) already exists.";
            show_error($txt);
            return false;
        } else {
            echo $filename = $filepart['filename'] . '.' . $filepart['extension'];
        }
        echo $dest_file = $fullpath . $filename;
        //check for folder permission
        if (!is_writeable($fullpath)) {
            echo "<br>" . $fullpath;
            chmod($fullpath, 0777);
            //$message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?'), $fullpath);
            //						show_error($message);
            //						return;
        }
        // save temp file to gallery
        if (!@move_uploaded_file($temp_file, $dest_file)) {
            show_error(__('Error, the file could not moved to : ') . $dest_file);
            //continue;
        } else {
            $insert = "INSERT INTO " . $pictures . " (pid, gid, filename, description, title) \t \t\t\t\t\t\t\t\t\t\t\t \t\t\t\t\t\t\t\t" . "VALUES ('', '" . $gid . "', " . $file_name . "', '" . $desc . "', '" . $title . "')";
            $results = $wpdb->query($insert);
            if ($results) {
                ?>
								<div class="updated" id="message" style="background-color: rgb(255, 251, 204);"><p>      											 								<?php 
                echo 'New Gallery added successfully!';
                ?>
</p></div>
								<?php 
            }
        }
        //if ( !chmod($dest_file) )
        //					{
        //						show_error(__('Error, the file permissions could not set'));
        //						continue;
        //					}
    }
    return;
}
예제 #8
0
function getdfiles($path, $exclude = array())
{
    $files = getfiles($path, $exclude);
    $dfiles = array();
    foreach ($files as $file) {
        $dfiles[] = fileinfo($path . $file);
    }
    return $dfiles;
}