CSV → JSON Converter (PHP)
This project demonstrates file-upload handling, CSV parsing, JSON encoding, and file I/O in pure PHP — no frameworks, no dependencies.
The page lets a user:
- Upload a
.csvfile. - Convert its contents into a structured JSON array.
- Save the JSON to a local text file (
output.txt). - Display the formatted JSON on screen in a scrollable textarea.
Everything runs in-browser with plain PHP.
- Secure file upload (
move_uploaded_file) - Automatic folder creation (
mkdir) - CSV parsing with
fgetcsv() - Clean data handling (skips blank/mismatched rows)
- JSON conversion using
json_encode(..., JSON_PRETTY_PRINT) - File writing with
file_put_contents() - Human-readable display inside
<textarea readonly>
- Ensure PHP 8+ is installed.
- From the project directory, start PHP’s built-in server: php -S localhost:3000 In your browser, visit ➡️ http://localhost:3000/project2.php
Choose a CSV file (e.g. sample.csv) and click Upload & Convert.
See the formatted JSON output below the form.