hat sayısı yol sorunu

4 Cevap php

$f="../mts/sites/default/files/test.doc"; / / bu şekilde i hat sayısını bulmak mümkün duyuyorum, ama ben $safe_filename olarak yol vermek ve {if i .. satır sayımı için klasör yolunu nasıl verebilirim almıyorum [(2)]} Geliyor dosya içeriği açılarak değil. Kodunu kontrol ve teşekkür peşin bana yardım edin

<?php
$nid = 1;
$teaser = false;

// Load node
$node = node_load(array('nid' => $nid));
// Prepare its output
if (node_hook($node, 'view')) {
  node_invoke($node, 'view', $teaser, false);
}
else {
  $node = node_prepare($node, $teaser);
}
// Allow modules to change content before viewing.
node_invoke_nodeapi($node, 'view', $teaser, false);

// Print
print $teaser ? $node->teaser : $node->body;

$target_path = "../mts/sites/default/files/ourfiles/";


//$myfile = basename( $_FILES['uploadedfile']['name']);

$safe_filename = preg_replace( 
                     array("/\s+/", "/[^-\.\w]+/"), 
                     array("_", ""), 
                     trim($_FILES['uploadedfile']['name']));

$target_path = $target_path.$safe_filename;

if(file_exists($target_path))
      {
      echo "<script language=\"javascript\">";
      echo "window.alert ('File already exist');";
      echo "//--></script>";
      }
elseif(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

echo "<script language=\"javascript\">";
echo "window.alert ('File uploaded succesfully');";
echo "//--></script>";


/*   
echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
*/

} 



$con = mysql_connect("localhost","mts","mts");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create table
mysql_select_db("mts", $con);



 $f="../mts/sites/default/files/test.doc";//in this way i am able to find line count,but i am not getting how i can give folder path for line counting


    // count words
    $numWords = str_word_count($str)/11;
    echo "This file have ". $numWords . " words";
echo "This file have ". $numWords . " lines";





mysql_query("INSERT INTO mt_upload (FileName,linecount, FilePath,DateTime)
VALUES ('".$safe_filename."','".$numWords."', '".$target_path.$safe_filename."',NOW())");


// Execute query
mysql_query($sql,$con);

mysql_close($con);
?>

emphasized text

4 Cevap

Bu şeyler yapmanın çok güvenli bir yol değildir. If two users submitted files with the same filename, they would overwrite each other. Bu sistemi çalıştıran bir süre sonra bir sorun haline benzersiz bir dosya adı, kullanıcı sınırlar. O hiç böyle bir mesaj aldım eğer kullanıcı oldukça şaşkın olacağını cabası.

Bir çok daha iyi bir çözüm, her dosya için kendi dosya üretmektir. Uzun bir rasgele bir dize yapmak, ya da belki mt_upload tabloda eklenen kayıt için mysql_insert_id() sürebilir. Sonra da regexplerde etrafında karışıklık gerek olmaz ve her şey çok daha kolay olurdu. Eğer kullanıcı veya bir şey göstermek istiyorum mt_upload tabloda, eski dosya tutabilirsiniz.

Bu tam kodu varsa, o sorun $str üzerine str_word_count() diyoruz ama her yerde $str ayarlamak için görünmüyor olmasıdır.

Belirli bir klasör içinde bulunan tüm dosyaları satırları saymak için Fonksiyon

function linecount_dir($dir) {
    $ig = array('.','..');
    $d = dir($dir);
    while (false !== ($entry = $d->read())) {
       if (!in_array($entry,$ig)) {
        $total += linecount($d->path . "/$entry");
       }
    }
    $d->close();
    return $total;
}

Satırları saymak için Fonksiyon

define(BLOCK_SIZE,131072);

function linecount($filename) {
    $f = fopen($filename,'r');
    while (!feof($f)) {
    $d = fread($f,BLOCK_SIZE);
    $rcount += substr_count($d, "\n");
    $ncount += substr_count($d, "\r");
    }
    fclose($f);
    return (($rcount >= $ncount) ? $rcount : $ncount);
}

Kodunuzu Uygulanan

$f="../mts/sites/default/files/test.doc";//in this way i am able to find line count,but i am not getting how i can give folder path for line counting

// count words
$numWords = str_word_count($str)/11;
// count lines
$numLines = linecount($f);

echo "This file have ". $numWords . " words";
echo "This file have ". $numLines . " lines";

".. / Mt / sites / default / files /". $ F = $ safe_filename;