PHP object Type Casting In Hindi | PHP object In Hindi
PHP filter_var() Function In Hindi | filter_var() In PHP In Hindi
PHP null In Hindi | PHP is null Function
PHP Program to check whether number is Palindrome or not | PHP Find Palindrome Number
PHP Error Control Operator In Hindi | Error Control In PHP
Java Program to check whether number is Palindrome or not | Java Find Palindrome Number
local Storage In JavaScript In Hindi | JS local Storage In Hindi
Linux netstat Command : Linux Networking
Logical Operators In JavaScript In Hindi | JS Logical Operators In Hindi
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 ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook