403Webshell
Server IP : 173.209.174.21  /  Your IP : 216.73.216.89
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64
User : nodor ( 1000)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/wcfs/tabs/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/wcfs/tabs//insert_blank_rows.php
<?php
// insert_blank_rows.php
// Upload a CSV and insert a blank row after every row starting at the chosen row (default 6).
// No external libraries required.

declare(strict_types=1);

// ---- Handle POST (file processing) ----
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $startRow = isset($_POST['start_row']) ? max(1, (int)$_POST['start_row']) : 6;
    $delimiter = $_POST['delimiter'] ?? ',';
    $delimiter = in_array($delimiter, [",", ";", "\t"]) ? $delimiter : ",";

    if (!isset($_FILES['csv']) || $_FILES['csv']['error'] !== UPLOAD_ERR_OK) {
        http_response_code(400);
        echo "Upload failed. Please go back and try again.";
        exit;
    }

    $tmp = $_FILES['csv']['tmp_name'];
    $origName = $_FILES['csv']['name'] ?? 'input.csv';

    // Open input
    $in = fopen($tmp, 'r');
    if (!$in) {
        http_response_code(400);
        echo "Could not read uploaded file.";
        exit;
    }

    // Create temp output file
    $outPath = tempnam(sys_get_temp_dir(), 'csvblank_');
    $out = fopen($outPath, 'w');
    if (!$out) {
        fclose($in);
        http_response_code(500);
        echo "Could not prepare output file.";
        exit;
    }

    // Detect max columns from first non-empty row (for optional consistent blank rows)
    $maxCols = 0;
    $buffer = [];
    $lineNum = 0;

    // We�ll do a first pass reading everything into $buffer, but still streaming-friendly for normal-sized CSVs.
    // If you expect huge CSVs (hundreds of MB), switch to a pure streaming approach below.
    while (($row = fgetcsv($in, 0, $delimiter)) !== false) {
        $buffer[] = $row;
        if ($row !== [null] && $row !== false) {
            $maxCols = max($maxCols, count($row));
        }
        $lineNum++;
    }
    fclose($in);

    // Write out with inserted blanks
    $currentRowNumber = 1;
    foreach ($buffer as $row) {
        // Write the current row
        fputcsv($out, $row, $delimiter);

        // If we�re at/after startRow, add a blank row *after* each data row
        if ($currentRowNumber >= $startRow) {
            // Option A: truly blank line (Excel treats as empty row)
            // fwrite($out, PHP_EOL);

            // Option B (safer when strict parsers are used): write an empty CSV row
            // with the same number of columns (appears blank in Excel).
            fputcsv($out, array_fill(0, $maxCols, ''), $delimiter);
        }

        $currentRowNumber++;
    }

    fclose($out);

    // Prepare download filename
    $ext = pathinfo($origName, PATHINFO_EXTENSION);
    $base = pathinfo($origName, PATHINFO_FILENAME);
    $downloadName = $base . "_with_blank_rows.csv";

    // Send the file
    header('Content-Type: text/csv; charset=utf-8');
    header('Content-Disposition: attachment; filename="' . $downloadName . '"');
    header('Content-Length: ' . filesize($outPath));
    readfile($outPath);
    @unlink($outPath);
    exit;
}
?>

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Insert Blank Rows in CSV</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
  body { font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; margin: 2rem; }
  .card { max-width: 720px; margin: auto; border: 1px solid #ddd; border-radius: 12px; padding: 1.5rem; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }
  h1 { margin-top: 0; }
  label { display:block; margin:.6rem 0 .25rem; font-weight:600; }
  input[type="file"], select, input[type="number"] { width: 100%; padding:.6rem; border:1px solid #ccc; border-radius:8px; }
  .row { display:flex; gap:1rem; }
  .row > div { flex:1; }
  button { margin-top:1rem; padding:.75rem 1rem; border:none; border-radius:10px; background:#0d6efd; color:#fff; font-weight:700; cursor:pointer; }
  button:hover { opacity:.95; }
  .tips { font-size:.95rem; color:#444; background:#f7f7f9; padding:1rem; border-radius:10px; margin-top:1rem; }
</style>
</head>
<body>
  <div class="card">
    <h1>Insert Blank Rows in CSV</h1>
    <form method="post" enctype="multipart/form-data">
      <label for="csv">CSV file</label>
      <input type="file" id="csv" name="csv" accept=".csv" required>

      <div class="row">
        <div>
          <label for="start_row">Start inserting after row�</label>
          <input type="number" id="start_row" name="start_row" value="6" min="1" required>
        </div>
        <div>
          <label for="delimiter">Delimiter</label>
          <select id="delimiter" name="delimiter">
            <option value=",">Comma (,)</option>
            <option value=";">Semicolon (;)</option>
            <option value="\t">Tab</option>
          </select>
        </div>
      </div>

      <button type="submit">Generate CSV</button>

      <div class="tips">
        <strong>How to use:</strong>
        <ol>
          <li>In Excel: File ? Save As ? CSV (Comma delimited) for the sheet you want.</li>
          <li>Upload the CSV here and set the start row (default is 6).</li>
          <li>Download the new CSV and open it in Excel.</li>
        </ol>
        Notes:
        <ul>
          <li>Rows <em>before</em> the start row are untouched.</li>
          <li>From the start row onward, a blank row is inserted <em>after</em> every row.</li>
          <li>If you need an .xlsx version later, we can add a PhpSpreadsheet path.</li>
        </ul>
      </div>
    </form>
  </div>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit