-4

I upload a file say 'example.csv'...How do I store 'example' inside a variable using php so as to create a table in the database having the table name as 'example'?

3 Answers3

5

One way is to use pathinfo():

http://php.net/pathinfo

$filename = "example.csv";
$dbname = pathinfo($filename, PATHINFO_FILENAME); // $dbname is now "example"
jszobody
  • 28,495
  • 6
  • 61
  • 72
2
$filename = "example.csv";
//Find the position of the last occurrence of "."

$point_pos = strrpos($filename,".");

//the second argument of substr is the length of the substring
$target = substr($filename, 0, $point_pos);
1

Another way is to use basename() function:

<?php

// your file
$file = 'example.csv';

$info = pathinfo($file);
$file_name =  basename($file,'.'.$info['extension']);

echo $file_name; // outputs 'example'

?>
mitkosoft
  • 5,262
  • 1
  • 13
  • 31