I have this code which outputs the file. The only issue is it keeps the entire directory with it. How would I remove all the directory so it would run correctly? I have tried a few things but they are commented out. include 'config.php'; // Fetch Record from Database $base = "/var/files/files/files/exportsomething.csv"; $filename = $_FILES['file']['name']; if (@is_uploaded_file($_FILES["file"]["tmp_name"])) { copy($_FILES["file"]["tmp_name"], "$base" . "$filename"); } $filename = $base . $filename; $output = ""; $table = "kick"; // 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 - 1; $i++) { $heading = mysql_field_name($sql, $i); if($i!=0) $output .= "|"; $output .= $heading; } $output .="\n"; // Get Records from the table while ($row = mysql_fetch_array($sql)) { for ($i = 0; $i < $columns_total - 1; $i++) { if($i!=0) $output .= "|"; $output .= $row["$i"]; } $output .="\n"; } // save the file $file = fopen($filename,"w"); fwrite($file, $output) or die("can't save the file"); fclose($file); //archive it $zip = new ZipArchive(); $zip->open($filename.".zip", ZipArchive::OVERWRITE); //$zip->addFile("${path}/".$filename.".csv", $filename.".csv"); //$new_filename = substr($file,strrpos($file,'/') + 1); //$zip->addFile($file,$new_filename); //addFolderToZip("$filename/", $zip); $zip->addFile($filename); $zip->close(); echo "zip file created"; PHP:
ok I figured out what I did wrong.. I just needed to change $file to $filename.. //$new_filename = substr($file,strrpos($file,'/') + 1); //$zip->addFile($file,$new_filename);