1
$org_file_name = $_FILES['file1']['name'];
$file_size = $_FILES['file1']['size'];
$ext = strtolower(pathinfo($org_file_name, PATHINFO_EXTENSION));
$file_path = 'docs/';
$rand = rand(111,999);          
if($ext == 'csv')
{
    if(file_exists($file_path))
    {
         $file_path = 'docs/'.$org_file_name;
    }
    if(!move_uploaded_file($_FILES['file1']['tmp_name'],$file_path))
    {
        die ('<script> alert("file not uploaded successfully."); </script>');
    }           
}
else
{
    die ('<script> alert("Uploaded only CSV files."); </script>');
}

In my code, csv files uploads but it doesn't rename it before saving into the database? I get the following error message:

Parse error: syntax error, unexpected ';' on line 28 Parse error: syntax error, unexpected 'echo' (T_ECHO) on line 29

How can I rename them? and how can I fetch this file from database.

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Elixir
  • 287
  • 2
  • 3
  • 14

1 Answers1

0

from the PHP Docs (move_uploaded_file):

bool move_uploaded_file ( string $filename , string $destination )

(...) If the file is valid, it will be moved to the filename given by destination.

so you just have to change your $file_path to the path + filename you want, for example: documents/csv/myfile.csv

low_rents
  • 4,481
  • 3
  • 27
  • 55