Menu
hi;
usually when you want to open a file, you use the following code or fopen to grab a file:
$yourdata = file_get_contents(“abc.txt”);
now what if I want to have a choice, instead of going to code page
and change e.g. abc.txt to zzz.txt,
how can I have a browse button that when you click on it, it gives you the option to browse to your hard drive and select one file or multiple of files you want to bring to process with your script.
thanks for help.
[CODE]
<form method="POST" enctype="multipart/form-data" action=" ">
<input type="file" size="20" name="filename">
</form>
[/CODE]
[code=php]
$yourdata = file_get_contents("abc.txt");
$var1 = preg_split("/[s]+/", $yourdata);
[/code]
<i>
</i>print_r ($_FILES);
[code=php]
<?
$path = "./files";//relative path to dir with files
$show = array( '.txt', '.php', '.TXT', '.PHP' ); //Type of files to show
$dh = @opendir( $path );
$file_list = "<h3>Files:</h3><br>n";
while( false !== ( $file = readdir( $dh ) ) ){
$ext=substr($file,-4,4);
if(in_array( $ext, $show )){
$file_list .= "<a class=file href="javascript:void(open('get_contents.php?filename=$file','','top=50,left=50'));">$file</a><br>n";
}
}
closedir( $dh );
?>
<html>
<head>
<title>
Index of <?=$path?>:
</title>
</head>
<body>
<?
echo"<h1>Files in Directory: "$path"</h1>";
echo"$file_list";
?>
</body></html>
[/code]
[code=php]
<html>
<head>
<title>
</title>
</head>
<body>
<?
$path = "./files/"; //point to the dir containing your files
$filename=$_GET['filename'];
$file= file_get_contents($path.$filename);
echo "<pre>$file</pre>"
?>
</body></html>
[/code]
[code=php]
<?
$path = "./files/"; //point to the dir containing your files
$filename=$_GET['filename'];
$file= file_get_contents($path.$filename);
echo "<pre>$file</pre>"
?>
[/code]
[code=php]
$words = file_get_contents("abc.txt");
$var1 = preg_split("/[s]+/", $words);
[/code]
[code=php]
<?
$path = "./files";//relative path to dir with files
$show = array( '.txt', '.php', '.TXT', '.PHP' ); //Type of files to show
$dh = @opendir( $path );
$file_list = "<h3>Files:</h3><br>n";
while( false !== ( $file = readdir( $dh ) ) ){
$ext=substr($file,-4,4);
if(in_array( $ext, $show )){
$file_list .= "<a class=file href="javascript:void(open('get_contents.php?filename=$file','','top=50,left=50'));">$file</a><br>n";
}
}
closedir( $dh );
?>
<html>
<head>
<title>
Index of <?=$path?>:
</title>
</head>
<body>
<?
echo"<h1>Files in Directory: "$path"</h1>";
echo"$file_list";
$words = file_get_contents($file);
$var1 = preg_split("/[s]+/", $words);
// this two lines are only part of the script for word counting
?>
</body></html>
[/code]
[code=php]
$fileLocation = 'zz'; // this the folder that contain text files
$fileNames = array();
$dh = opendir($fileLocation) or die('error opening dir');
while (false !== ($file = readdir($dh)))
{
if ( trim($file, '.') != '' )
{
echo "file name : ".$file."<br>";
function isDir($dir) {
$cwd = getcwd();
$returnValue = false;
if (@chdir($dir)) {
chdir($cwd);
$returnValue = true;
}
return $returnValue;
}
$var2 = file_get_contents("domedata.csv");
$var2 = explode('%%', $var2);
$allwords = file_get_contents("$file"); // this should read files from folder
$var1 = preg_split("/[s]+/", $allwords);
$i = 0;
$j = 1;
$numofwords = 30;
while($i < sizeof($var1)){
if($j == $numofwords+1){
$randnum = rand(0, count($var2)-1);
array_splice($var1, $i, 0, array($var2[$randnum]));
$j = 0;
}
$j++;
$i++;
}
$var2 = implode(" ", $var1);
$fp = fopen( "new-text.txt", "w" ); // this write a single file
fwrite( $fp, $var2 );
}
}
closedir($dh);
[/code]
....
read a text file from a folder,
counting words of the text file, then insert some non English words/characters from another file(csv format) into the text (after a certain number of words)
then make a new file out of the result,
(in this example is called new-text.txt.)
Now I want to make the script read all text files inside the folder one by one,
( i will put text files in the folder, no need for the script to do that).
and then do the insertion one by one
and then write new text files one by one,
and then give a name to the files (possibly a variation of the file names that has been used), should be recognized which file belongs to which one,
e.g. aaa.txt becomes aaa_1.txt and so
or even rewrite the files.
...[/QUOTE]
I dont think people understood what the goal was, let me see if i understand:
You have some text files, and a CSV file in a directory
You want to
[LIST=1]
[*]open a text file [*]read from a CSV [*]Insert a word from the CSV (after every 5th word in the text file) [*]Save the modified file as a revision
[/LIST]
Do you use the same csv file on every text file?
Does the CSV file need to be in specific format...or can it just be a text file containing the words you want to insert?[/QUOTE]
[code=php]
$temp .= ($insert_count != 0) ? "".trim($inserts[$insert_count])." " : "";
[/code]
[code=php]
$temp .= ($insert_count != 0) ? "".trim($inserts[$insert_count])." " : "text inserted at beginning of file";
[/code]
0.1.9 — BETA 5.8