PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
As i am working on file upload concept in php. When i browse the csv file from any directory to upload data to mysql i am getting the following error. Apart from getting errors the empty records are added to the mysql database and also the script will continue executing.(which goes to the infinite loop)
Warning: fopen() [function.fopen]: Filename cannot be empty in C:\xampp\htdocs\upload\import1.php on line 11
Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\upload\import1.php on line 13
A global $_FILES contains an array of sended files. So it has name of your "input" on firstlevel in case of sending datas throught html form. I have experience with some java uploader and it uses a bit different ordering.
Important is that you have to identified a name of your file input.
I want to upload the csv file which is not in a particular folder but the csv file will be anywhere in the system. I want to browse that file and upload it to the mysql database.. Further clarifaction required..
I hope I understand. It's possible that I can't write my suggestion properly. So I will try it again, sorry if it will be to particular.
PHP is a server side language, so you need to move the csv file from your machine to a server. It's possible throught "<input type="file" name="filename' />" as you have in your html. This tag will cause this:
The file will be copied from your machine to a server's temp.
Your target script will receive the global variable $_FILES. The variable has,in your case, this form:
$_FILES['filename']['tmp_name'] = '/tmp/somename'; //path to the file on server - the only possible way how to reach the file
$_FILES['filename']['name'] = 'file_name'; //the name of file -> string; this is not a path!
... and some other values http://us3.php.net/manual/en/reserved.variables.files.php
So If you want operate with your csv you have to use 'tmp_name'. In your script will be in the var $filename an array.