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;
exit;
*****************************************
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
jpizzolato
0
Newbie Poster
Recommended Answers
Jump to Postso all you want is to upload a file?
do you have a folder for uploaded file?
Jump to PostI 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.
Jump to PostTry rename function link
<?php rename("/tmp/tmp_file.php", "/home/user/login/docs/my_file.php"); ?>
All 9 Replies
jj.dcruz
0
Junior Poster

diafol
jpizzolato
0
Newbie Poster
gabrielcastillo
40
Web Developer
Mike_danvers
0
Junior Poster in Training

diafol
sikander123
0
Newbie Poster

diafol
sikander123
0
Newbie Poster
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.