PHP file browse upload issue

So i have this code that is supposed to upload a csv file and send it to php. the issue i am having is this error: Warning: fopen() [function.fopen]: Filename cannot be empty in /Quick_CSV_import.php on line 83

now, I believe i know what the problem is but i just don’t know how to fix it. I think it is not seeing the actual file. The browse option is there but it won’t actually “see” the file or the contents of said file before the upload. here is the set of code the error is.

[php]function get_csv_header_fields()
{
$this->arr_csv_columns = array();
$fpointer = fopen($file_name, “r”);
if ($fpointer)
{
$arr = fgetcsv($fpointer, 10*1024, $this->field_separate_char);
if(is_array($arr) && !empty($arr))
{
if($this->use_csv_header)
{
foreach($arr as $val)
if(trim($val)!="")
$this->arr_csv_columns[] = $val;
}
else
{
$i = 1;
foreach($arr as $val)
if(trim($val)!="")
$this->arr_csv_columns[] = “column”.$i++;
}
}
unset($arr);
fclose($fpointer);
}
else
$this->error = “file cannot be opened: “.(””==$this->file_name ? “[empty]” : @mysql_escape_string($this->file_name));
return $this->arr_csv_columns;
}[/php]

here is where the file is supposedly defined:

[php]class Quick_CSV_import
{
var $table_name = “”; //where to import to
var $file_name; //where to import from
var $use_csv_header; //use first line of file OR generated columns names
var $field_separate_char; //character to separate fields
var $field_enclose_char; //character to enclose fields, which contain separator char into content
var $field_escape_char; //char to escape special symbols
var $error; //error message
var $arr_csv_columns; //array of columns
var $table_exists; //flag: does table for import exist
var $encoding; //encoding table, used to parse the incoming file. Added in 1.5 version

function Quick_CSV_import()
{
$this->file_name = $file_name;
$this->arr_csv_columns = array();
$this->use_csv_header = true;
$this->field_separate_char = “,”;
$this->field_enclose_char = “”";
$this->field_escape_char = “\”;
$this->table_exists = false;
}[/php]

and this is the part of the form:

<tr> <td>Source CSV file to import:</td> <td rowspan="30" width="10px">&nbsp;</td> <td><input type="file" name="file_source" id="file_source" class="edt" value="<?=$file_source?>"></td> </tr>

if there is any help I would appreciate it.

Hi,

In which folder you upload the file. Set that folder permission to 777.

Sponsor our Newsletter | Privacy Policy | Terms of Service