PHP Error Control Operator In Hindi | Error Control In PHP
PHP Interview Questions In Hindi : PHP Interview Preparation
PHP object Type Casting In Hindi | PHP object In Hindi
PHP null In Hindi | PHP is null Function
Linux adduser Command In Hindi
What is OSI Model In Hindi | Layers of OSI model
JavaScript Spread syntax In Hindi : Spread Operator In JavaScript
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
PHP Import CSV File
File : csv_import.html
<html>
<head>
<title>PHP Import CSV File</title>
</head>
<body>
<form action="./csv_import.php" method="POST" enctype=multipart/form-data>
<p><input type="file" name="myfile" multiple></p>
<p><button type="submit">Submit</button></p>
</form>
</body>
</html>
File : csv_import.php
<?php
// check if file is coming.
if(isset($_FILES['myfile']))
{
//first open file in READ mode.
if (($handle = fopen($_FILES['myfile']['tmp_name'], "r")) !== FALSE)
{
//here we will get every row as an array.
$csv_data = [];
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$num = count($data);
if($num > 0)
{
// push row in an array.
$csv_data[] = $data;
}
}
// close file
fclose($handle);
// now print data.
echo "<pre>";
print_r($csv_data);
echo "</pre>";
}
else
{
echo "File is not readable";
}
}
?>
fopen() function का use file को open करने के लिए किया जाता है , example में file को r mode के साथ file को open किया गया है क्योंकि यहां हमें सिर्फ file को read करना है। आप अपनी need के according file को दुसरे mode में भी open कर सकते हैं।
fgetcsv() function का use open CSV file की line को read करने के लिए use किया जाता है। यह function csv file की single line को separator (by default ,
) और enclosure (by default "
) के bases पर array return करता है।
यह function open file pointer को close करता है।
Loading ...
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook