I am trying to upload a csv file to a website that was created using a MySQL query in a php file. Here is the code:
// Fetch Record from Database

$output = "";
$table = "customer"; // Enter Your Table Name 
$sql = mysql_query("select * from $table");
$columns_total = mysql_num_fields($sql);

// Get The Field Name

    for ($i = 0; $i < $columns_total; $i++) {

$heading = mysql_field_name($sql, $i);
$output .= '"'.$heading.'",';
$output .="\n";

// Get Records from the table

while ($row = mysql_fetch_array($sql)) {
for ($i = 0; $i < $columns_total; $i++) {
$output .='"'.$row["$i"].'",';
$output .="\n";

// Download the file

$filename = "myFile.csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);

echo $output;
All this code is doing is displaying the results in the browser. 
My problem is how do I get the myFile.csv uploaded to the following directory:
http://eztiffin.com/fileuploads/    I need to get the actual path from my hosting company

Any help would be appreciated. thanks

Recommended Answers

All 9 Replies

so all you want is to upload a file?
do you have a folder for uploaded file?

Member Avatar for diafol

I don't think I understand, you want to create a file on the server from data ... on the server? So you really don't want an upload at all - just create a file. Is that right?

You can do this easily with file_put_contents(). Check out the php manual.

You are correct. The file is being created by a php file on the same server. I guess what I want to do is move it to a specific folder. In looking at the code I provided where is the file being created, in the php file? I didn't see it there. How do I move it? What should the next instruction be? Do I use the file_put_contents() to do that?

Thanks for everyone's help.

Try rename function link

rename("/tmp/tmp_file.php", "/home/user/login/docs/my_file.php");

though i dnt know much but on line 7 instead of $table i would suggest you to try the "table name" as it is in you mysql database.n use the datatype as "blob" for storing.it worked for me.

Member Avatar for diafol

As I see it there are a couple of parts to your work.

The creation of the file and the location of the file.

If you want to create and locate at the same time - use file_put_contents()
If you just want to move an existing file - you can use rename()

            $file               =      $_FILES['video']['name'];
            $path               =      PATH_DIR.'video/';
            $upload_file        =      $path.$file;
            $source_image_path  =      PATH_DIR.'video/';

            $data['video']      =   $file;

// this is the code for uploading a video file you can get help from this
Member Avatar for diafol

^^ Read all posts, he admits that he does not want to upload files.

Try This :

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.