Edit File by line
/home/barbar84/www/extracte.../filemang...
File: delete_line.php
<?php
[0] Fix | Delete
[1] Fix | Delete
[2] Fix | Delete
const ACCESS = true;
[3] Fix | Delete
[4] Fix | Delete
include_once 'function.php';
[5] Fix | Delete
[6] Fix | Delete
[7] Fix | Delete
$title = 'Delete the line';
[8] Fix | Delete
$page = array('current' => 0, 'paramater_0' => null, 'paramater_1' => null);
[9] Fix | Delete
$page['current'] = isset($_GET['page']) ? intval($_GET['page']) : 1;
[10] Fix | Delete
$page['current'] = $page['current'] <= 0 ? 1 : $page['current'];
[11] Fix | Delete
[12] Fix | Delete
include_once 'header.php';
[13] Fix | Delete
[14] Fix | Delete
echo '<div class="title">' . $title . '</div>';
[15] Fix | Delete
[16] Fix | Delete
if ($dir == null || $name == null || !is_file(processDirectory($dir . '/' . $name))) {
[17] Fix | Delete
echo '<div class="list"><span>The path does not exist</span></div>
[18] Fix | Delete
<div class="title">Function</div>
[19] Fix | Delete
<ul class="list">
[20] Fix | Delete
<li><img src="icon/list.png"/> <a href="index.php' . $pages['paramater_0'] . '">List</a></li>
[21] Fix | Delete
</ul>';
[22] Fix | Delete
} else if (!isFormatText($name) && !isFormatUnknown($name)) {
[23] Fix | Delete
echo '<div class="list"><span>This file is not in text format</span></div>
[24] Fix | Delete
<div class="title">Function</div>
[25] Fix | Delete
<ul class="list">
[26] Fix | Delete
<li><img src="icon/list.png"/> <a href="index.php?dir=' . $dirEncode . $pages['paramater_1'] . '">List</a></li>
[27] Fix | Delete
</ul>';
[28] Fix | Delete
} else {
[29] Fix | Delete
function process()
[30] Fix | Delete
{
[31] Fix | Delete
global $content, $lines, $count, $path;
[32] Fix | Delete
[33] Fix | Delete
$content = file_get_contents($path);
[34] Fix | Delete
[35] Fix | Delete
if (strlen($content) > 0) {
[36] Fix | Delete
$content = str_replace("\r\n", "\n", $content);
[37] Fix | Delete
$content = str_replace("\r", "\n", $content);
[38] Fix | Delete
[39] Fix | Delete
if (strpos($content, "\n") !== false)
[40] Fix | Delete
$lines = explode("\n", $content);
[41] Fix | Delete
else
[42] Fix | Delete
$lines[] = $content;
[43] Fix | Delete
} else {
[44] Fix | Delete
$lines[] = $content;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
$count = count($lines);
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
$path = $dir . '/' . $name;
[51] Fix | Delete
$line = isset($_GET['line']) ? intval($_GET['line']) : 0;
[52] Fix | Delete
$content = null;
[53] Fix | Delete
$notice = null;
[54] Fix | Delete
$lines = array();
[55] Fix | Delete
$count = 0;
[56] Fix | Delete
[57] Fix | Delete
if ($page['current'] > 1) {
[58] Fix | Delete
$page['paramater_0'] = '?page=' . $page['current'];
[59] Fix | Delete
$page['paramater_1'] = '&page=' . $page['current'];
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
process();
[63] Fix | Delete
[64] Fix | Delete
if (isset($_POST['continue']) || isset($_POST['delete'])) {
[65] Fix | Delete
$data = null;
[66] Fix | Delete
[67] Fix | Delete
if ($count > 1) {
[68] Fix | Delete
if ($line > 0) {
[69] Fix | Delete
for ($i = 0; $i < $line; ++$i)
[70] Fix | Delete
$data .= $lines[$i] . ($i < $line - 1 ? "\n" : null);
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
if ($line < $count - 1) {
[74] Fix | Delete
for ($i = ($line + 1); $i < $count; ++$i)
[75] Fix | Delete
$data .= ($i > 1 || $line > 0 ? "\n" : null) . $lines[$i];
[76] Fix | Delete
}
[77] Fix | Delete
} else {
[78] Fix | Delete
$data = null;
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
if (file_put_contents($path, $data)) {
[82] Fix | Delete
$notice = '<div class="notice_succeed">Delete successfully</div>';
[83] Fix | Delete
[84] Fix | Delete
if (isset($_POST['delete']))
[85] Fix | Delete
goURL('edit_text_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . $page['paramater_1'] . '#line_number_' . ($line > $count - 2 ? $count - 2 : $line));
[86] Fix | Delete
} else {
[87] Fix | Delete
$notice = '<div class="notice_failure">Delete failure</div>';
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
process();
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
$isGO = false;
[94] Fix | Delete
[95] Fix | Delete
if (isset($_POST['go']) && !empty($_POST['line']) && preg_match('#\\b[0-9]+\\b#', $_POST['line'])) {
[96] Fix | Delete
$li = intval($_POST['line']);
[97] Fix | Delete
[98] Fix | Delete
if ($li >= 0 && $li <= $count - 1) {
[99] Fix | Delete
$line = $li;
[100] Fix | Delete
$isGO = true;
[101] Fix | Delete
}
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
if ($line < 0)
[105] Fix | Delete
goURL('delete_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=0' . $page['paramater_1']);
[106] Fix | Delete
[107] Fix | Delete
if ($line > $count - 1)
[108] Fix | Delete
goURL('delete_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . ($count - 1) . $page['paramater_1']);
[109] Fix | Delete
[110] Fix | Delete
$page['current'] = $line + 1 > $configs['page_file_edit_line'] ? ceil(($line + 1) / $configs['page_file_edit_line']) : 1;
[111] Fix | Delete
[112] Fix | Delete
if ($page['current'] > 1) {
[113] Fix | Delete
$page['paramater_0'] = '?page=' . $page['current'];
[114] Fix | Delete
$page['paramater_1'] = '&page=' . $page['current'];
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
if ($isGO)
[118] Fix | Delete
goURL('delete_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . $line . $page['paramater_1']);
[119] Fix | Delete
[120] Fix | Delete
$url = array('action' => null, 'prev' => null, 'next' => null);
[121] Fix | Delete
$url['action'] = 'delete_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . $line . $page['paramater_1'] . '#line_label';
[122] Fix | Delete
$url['prev'] = $line > 0 ? '<a href="delete_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . ($line - 1) . ($configs['page_file_edit_line'] > 0 && $line <= $configs['page_file_edit_line'] ? null : '&page=' . ceil($line / $configs['page_file_edit_line'])) . '#line_label"><img src="icon/arrow_left.png"/></a>' : '<img src="icon/arrow_left.png"/>';
[123] Fix | Delete
$url['next'] = $line < $count - 1 ? '<a href="delete_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . ($line + 1) . ($configs['page_file_edit_line'] > 0 && $line <= $configs['page_file_edit_line'] ? null : '&page=' . ceil(($line + 2) / $configs['page_file_edit_line'])) . '#line_label"><img src="icon/arrow_right.png"/></a>' : '<img src="icon/arrow_right.png"/>';
[124] Fix | Delete
[125] Fix | Delete
echo $notice;
[126] Fix | Delete
echo '<div class="list">
[127] Fix | Delete
<span class="bull">&bull; </span><span>' . printPath($dir, true) . '</span><hr/>
[128] Fix | Delete
<div class="ellipsis break-word">
[129] Fix | Delete
<span class="bull">&bull; </span>File: <strong class="file_name_edit">' . $name . '</strong>
[130] Fix | Delete
</div><hr/>
[131] Fix | Delete
<span class="bull" id="line_label">&bull; </span>Dòng [<strong class="line_number_form">' . $line . '</strong>/<strong class="line_number_form">' . ($count - 1) . '</strong>]:
[132] Fix | Delete
<div class="box_text break-word">
[133] Fix | Delete
<span>' . htmlspecialchars($lines[$line]) . '</span>
[134] Fix | Delete
</div>
[135] Fix | Delete
<div style="margin-left: -4px">
[136] Fix | Delete
<form action="delete_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . $line . $page['paramater_1'] . '#line_label" method="post">
[137] Fix | Delete
<input type="submit" name="continue" value="Tiếp tục"/>
[138] Fix | Delete
<input type="submit" name="delete" value="Delete"/>
[139] Fix | Delete
<a href="edit_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . $line . $page['paramater_1'] . '" id="href_line_edit">Fix</a>
[140] Fix | Delete
</form>
[141] Fix | Delete
</div><hr/>
[142] Fix | Delete
<form action="' . $url['action'] . '" method="post">
[143] Fix | Delete
<table id="action_page">
[144] Fix | Delete
<tr>
[145] Fix | Delete
<td id="prev">' . $url['prev'] . '</td>
[146] Fix | Delete
<td id="input">
[147] Fix | Delete
<input type="text" name="line" value="' . $line . '"/>
[148] Fix | Delete
</td>
[149] Fix | Delete
<td id="submit">
[150] Fix | Delete
<input type="submit" name="go" value="Đến"/>
[151] Fix | Delete
</td>
[152] Fix | Delete
<td id="next">' . $url['next'] . '</td>
[153] Fix | Delete
</tr>
[154] Fix | Delete
</table>
[155] Fix | Delete
</form>
[156] Fix | Delete
</div>
[157] Fix | Delete
<div class="tips">
[158] Fix | Delete
<img src="icon/tips.png"/>
[159] Fix | Delete
<span>Ấn tiếp tục để Delete và ở lại trang, ấn Delete để Delete và quay về List dòng</span>
[160] Fix | Delete
</div>
[161] Fix | Delete
<div class="title">Function</div>
[162] Fix | Delete
<ul class="list">
[163] Fix | Delete
<li><img src="icon/edit.png"/> <a href="edit_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . $line . $page['paramater_1'] . '">Fix dòng</a></li>
[164] Fix | Delete
<li><img src="icon/edit_text_line.png"/> <a href="edit_text_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . $page['paramater_1'] . '#line_number_' . $line . '">Edit by line</a></li>
[165] Fix | Delete
<li><img src="icon/edit.png"/> <a href="edit_text.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Edit text</a></li>
[166] Fix | Delete
<li><img src="icon/download.png"/> <a href="file_download.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Download</a></li>
[167] Fix | Delete
<li><img src="icon/info.png"/> <a href="file.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Information</a></li>
[168] Fix | Delete
<li><img src="icon/rename.png"/> <a href="file_rename.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Rename</a></li>
[169] Fix | Delete
<li><img src="icon/copy.png"/> <a href="file_copy.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Copy</a></li>
[170] Fix | Delete
<li><img src="icon/Copy.png"/> <a href="file_Copy.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Move</a></li>
[171] Fix | Delete
<li><img src="icon/delete.png"/> <a href="file_delete.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Delete</a></li>
[172] Fix | Delete
<li><img src="icon/access.png"/> <a href="file_chmod.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Chmod</a></li>
[173] Fix | Delete
<li><img src="icon/list.png"/> <a href="index.php?dir=' . $dirEncode . $pages['paramater_1'] . '">List</a></li>
[174] Fix | Delete
</ul>';
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
[178] Fix | Delete
include_once 'footer.php';
[179] Fix | Delete
[180] Fix | Delete
?>
[181] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function