Upload a File in PHP

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Tue Feb 18, 2014 10:59 pm

Upload a File in PHP

Postby jpizzolato » Tue Feb 18, 2014 11:13 pm

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:

Any help would be appreciated. thanks

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 8 guests