Cannot remove the $ext from a variable. PHP/MySQL
<p>my index page have a input field where you can create a file. Under this input field I have a table of all created files, like this:</p>

<pre><code>Title     | Edit | Delete |
denis.txt   Edit   Delete
</code></pre>

<p>So I want to make 'something' (I don't know how), so the title in the table (denis.txt) to do not display the extension (.txt).</p>

<p>Here is my index file:</p>

<pre><code>&lt;form action="create_file.php" method="post" class="form-horizontal"/&gt;
                        &lt;label class="control-label"&gt;Заглавие:&lt;/label&gt;
                              &lt;div class="controls"&gt;
                                 &lt;input name="name" type="text" width="40" class="span6 m-wrap" /&gt;&lt;input type="submit" value="Продължи..." class="btn red"&gt;&lt;/input&gt;
                              &lt;/div&gt;
                           &lt;/div&gt;
                            &lt;/form&gt;
&lt;table class="table table-bordered table-hover"&gt;
                  &lt;thead&gt;
                    &lt;tr&gt;
                      &lt;th&gt;Заглавие&lt;/th&gt;
                      &lt;th style="align: center; width: 12%"&gt;&lt;div align="center"&gt;Редактирай&lt;/div&gt;&lt;/th&gt;
                      &lt;th style="align: center; width: 12%"&gt;&lt;div align="center"&gt;Изтрий&lt;/div&gt;&lt;/th&gt;
                    &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
&lt;?php
echo $_POST['edit'];
$full_path = ".";

$dir = @opendir($full_path) or die("Директорията не може да се отвори.");

while($file = readdir($dir))
{
  if($file == "components" || $file == "index-restricted.php" || $file == "index-error.php" || $file == "generalsettings-success.php" || $file == "exampic" || $file == "all_count.txt" || $file == "assets" || $file == "count_vhod.txt" || $file == "count_nachalo.txt" || $file == "index-invalid.php" || $file == "news-delok.php" || $file == "images" || $file == "auth.php" || $file == "php" || $file == "news.php" || $file == "sponsors.php" || $file == "upload" || $file == "js" || $file == "img" || $file == "dashboard.php" || $file == "logout.php" || $file == "ajax" || $file == "prettify" || $file == "log.php" || $file == "css" || $file == "generalsettings.php" || $file == "nachaloadm.php" || $file == "php_errorlog" || $file == "fonts" || $file == "sql.php" || $file == "edit_file.php" || $file == "delete.php" || $file == "create_file.php" || $file == ".." || $file == "index.php" || $file == "." || $file == "edit.php")

  continue;
?&gt; &lt;?php
  echo "&lt;tr&gt;&lt;td&gt;&lt;a href='$file'&gt;$file&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href='edit.php?name=$file' class='btn mini purple'&gt;&lt;div align='center'&gt;&lt;i class='icon-edit'&gt;&lt;/i&gt;&amp;nbsp;&amp;nbsp;Редактирай&lt;/div&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;div align='center'&gt;&lt;a href='delete.php?name=$file' class='btn mini black'&gt;&lt;div align='center'&gt;&lt;i class='icon-trash'&gt;&lt;/i&gt;&amp;nbsp;&amp;nbsp;Изтрий&lt;/div&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;";
}

closedir($dir);


?&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
</code></pre>

<p>Here is my create_file.php:</p>

<pre><code>&lt;?php
$pre_file_name = $_POST['name'];

$ext = ".txt";

$file_name = $pre_file_name.$ext;

fopen($file_name,'w');
?&gt;
&lt;form class="stdform stdform2" action="edit_file.php" method="POST"&gt;
    &lt;label&gt;Въведете новината (текст):&lt;/label&gt;&lt;span class="field"&gt;&lt;textarea class="input-xxlarge" name="edit" cols="1600" rows="10"&gt;&lt;/textarea&gt;&lt;/span&gt;&lt;p&gt;
    &lt;input type="hidden" name="file_name" value="&lt;?php echo $file_name; ?&gt;"&gt;
    &lt;p class="stdformbutton"&gt;
    &lt;input class="btn btn-primary" type="submit" value="Създай!"&gt;
&lt;/p&gt;
&lt;/form&gt;
</code></pre>

<p>Here is my edit_file.php:</p>

<pre><code>&lt;?php
$edit = $_POST['edit'];

$file_name = $_POST['file_name'];

$file = fopen($file_name, 'w');

fwrite($file,$edit);

fclose($file);

echo "File Saved! &lt;a href='index.php'&gt;Click here to continue&lt;/a&gt;"



?&gt;
</code></pre>

<p>A friend of mine wrote me the following:</p>

<pre><code>"If you use the explode function to separate the file name from the extension. So:
$array = explode(".",$file);
Then you can echo out:
echo $array[0]; which will give you the file name without the extension.
You may get some problems with this though if you have a dot in the file name, so more than one dot. But who uses dots in the file name anyway, but its something to think about.
Also this method might not be best with the while loop looping round the files in the readdir function.
You may be better using the scandir function which puts the files into any array then you can use a for each loop to loop through the array."
</code></pre>

<p>But I have no idea how to make it work.
P.S. I guess that it can be made with $_SESSION too, but either don't know how to make it :(</p>

<p>Regards,
Denis Saidov</p>
