hi,
hier mal das, was ich mir im internet zusammengesucht hab, doch leider geht da irgendwas net... bzw ich bin einfach zu dumm für ^^
wenn ich die datei auf dem server öffne, sagt der browser mir folgende fehlermeldung:
Fatal error: Cannot redeclare fputcsv() in /usr/export/www/vhosts/funnetwork/hosting/...homepageadresse.../form2csv1.php on line 203
Da ich mich damit gar nich auskenn, frag ich euch
hier mal das, was ich mir im internet zusammengesucht hab, doch leider geht da irgendwas net... bzw ich bin einfach zu dumm für ^^
PHP:
<?php
/*
* form2csv.php - Form Data Logger
* Copyright (c) 2003-08-18 by The M.I.P. <the_mip (at) gmx.fr>
* $Id: form2csv.php,v 1.3 2003/08/19 00:21:43 djoe Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// BEGIN Config
$formpage = 'testen.html'; // File name of HTML form - form action has to point towards this script
$exitpage = 'danke.html'; // File name of HTML exit page
$include_authinfo = true; // Set to false to not include $PHP_AUTH_USER and $PHP_AUTH_PW
$include_timestamp = true; // Set to false to not include current time
$timeformat = 'U'; // Time format as used by date() - see also http://php.net/date
$dedupe = 'PHP_AUTH_USER'; // Form field to check for dupes
$dupe = 'update'; // 'ignore', 'update' or 'append' dupe entries
$datadir = 'data/'; // Directory to hold the CSV files - must be writable by the webserver (chmod 0777)
$csvname = ''; // Common prefix for CSV files - might also be supplied e.g. via a hidden form field
// END Config
// BEGIN Main
//error_reporting(E_ALL);
error_reporting(7);
// Merge $_POST and $_GET vars into an array - $_REQUEST would'nt fit here as cookie data can be annoying
$formvars = array_merge($_POST, $_GET);
$prefix = 'data';
$bufsize = 32768; // Size of line buffer
if (empty($formvars)) {
if (is_file($formpage) && is_readable($formpage)) {
include($formpage);
exit;
} else {
// Spit out a small test form
?>
<title>form2csv Test Form</title>
<form action="form2csv.php" method="post">
<input type="hidden" name="csvname" value="form2csvtest"/>
<input type="text" name="foo" /><br />
<input type="text" name="bar[2]" /><br />
<input type="text" name="bar[1]" /><br />
<input type="text" name="foobar" /><br />
<input type="submit" />
</form>
<?php
exit;
}
}
if ($include_authinfo && isset($PHP_AUTH_USER) && isset($PHP_AUTH_PW)) {
$formvars['PHP_AUTH_USER']=$PHP_AUTH_USER;
$formvars['PHP_AUTH_PW']=$PHP_AUTH_PW;
}
if ($include_timestamp) {
$formvars['time']=date($timeformat,time());
}
if (!empty($formvars['csvname']) && empty($csvname)) {
// Make a sane csv data file prefix when csvname is supplied via form
$csvname = substr(urlencode(strtr($formvars['csvname'], ' ./\?&', '______')), 0, 32);
unset($formvars['csvname']);
}
if (!empty($csvname)) {
$prefix = $csvname;
$csvname .= '-';
}
// Reformat or display array
// Derived from a function found at http://www.devdump.com/phpxml.php
function flat_a($obj, $prefix='data', $ksort = 1, $outputmode = 0) {
static $__level_deep, $flatarr;
if (!isset($__level_deep) || $obj==='clear') {
$__level_deep = array();
}
if (!isset($flatarr) || $obj==='clear') {
$flatarr = array();
}
if ($obj==='clear') {
return;
}
if (is_object($obj)) {
if ($outputmode == 1) {
print '[obj]';
}
return $flatarr;
} elseif (is_array($obj)) {
if ($ksort > 0) {
ksort($obj);
}
foreach(array_keys($obj) as $keys) {
array_push($__level_deep, "[".$keys."]");
flat_a($obj[$keys], $prefix, $ksort, $outputmode);
array_pop($__level_deep);
}
return $flatarr;
} else {
if ($outputmode == 1) {
print $prefix.implode("",$__level_deep)." = $obj\n";
}
$flatarr_key = $prefix.implode("",$__level_deep);
$flatarr_val = $obj;
if (isset($flatarr_val)) {
$flatarr[]["{$flatarr_key}"] = $flatarr_val;
}
return $flatarr;
}
}
// Return flat array as csv
function flat_a2csv($arr, $header = 0) {
$line = '';
if ($header == 0) {
foreach(array_values($arr) as $vals) {
foreach(array_values($vals) as $keys) {
if (!empty($line)) {
$line .=',';
}
$line .= '"'.addslashes($keys).'"';
}
}
} else {
foreach(array_values($arr) as $vals) {
foreach(array_keys($vals) as $keys) {
if (!empty($line)) {
$line .=',';
}
$line .= '"'.addslashes($keys).'"';
}
}
}
return $line."\n";
}
// Generate a name which is unique for every different HTML form dataset
function arrayname($arr, $prefix='data') {
global $dedupe, $dedupe_num;
flat_a('clear');
$narr = flat_a($arr, $prefix);
unset($arr);
flat_a('clear');
$arrname = '';
$i=0;
foreach(array_values($narr) as $vals) {
foreach(array_keys($vals) as $keys) {
$arrname .= $keys;
if ($keys == "{$prefix}[{$dedupe}]") {
// Index of field to dedupe
$dedupe_num = $i;
}
$i++;
}
}
return md5($arrname);
}
// Based on a function posted on http://php.net/manual/de/function.fgetcsv.php
function fputcsv ($fp, $array, $deliminator=',', $enclosure='"') {
$alwaysenc = 1; // Always add enclosure
$line = '';
foreach($array as $val) {
// remove any windows new lines,
// as they interfere with the parsing at the other end
$val = str_replace("\r\n", "\n", $val);
if ($alwaysenc) {
$line .= $enclosure.addslashes($val).$enclosure.$deliminator;
} else {
// if a deliminator char, a double quote char or a newline
// are in the field, add quotes
if (ereg("[$deliminator\"\n\r]", $val)) {
$val = $enclosure.str_replace($enclosure, $enclosure.$enclosure, $val).$enclosure;
}
$line .= $val.$deliminator;
}
}
// strip the last deliminator
$line = substr($line, 0, (strlen($deliminator) * -1));
$line .= "\n";
// we don't care if the file pointer is invalid,
// let fputs take care of it
return fputs($fp, $line);
}
if (!is_dir($datadir) || !is_writable($datadir)) {
die("Error: Data dir '{$datadir}' is not writable!");
}
flat_a('clear');
$fla = flat_a($formvars, $prefix);
$csvname .= arrayname($formvars).'.csv';
$newfile = 0;
// Shared lock on source csv data file
$old = @fopen($datadir.'/'.$csvname, 'r') or $newfile = 1;
if ($newfile == 0) {
$oldstat = stat($datadir.'/'.$csvname);
if ($oldstat[8] == 0) {
// CSV exists, but contains no data
$newfile = 1;
} else {
flock($old, 1) or die("Error: Could not lock source file '".$datadir.'/'.$csvname."'");
}
}
// Exclusive lock on destination csv data file
$new = @fopen($datadir.'/'.$csvname.'.new', 'w');
flock($new, 2) or die("Error: Could not lock destination file '".$datadir.'/'.$csvname."'");
if ($newfile == 1) {
// Prepend header with field names
fputs($new, flat_a2csv($fla,1));
}
$dupe_found = 0;
$i = 0;
while($flb = @fgetcsv($old, $bufsize)) {
if ($i == 0) {
if (!strstr($flb[0], $prefix.'[')) {
// Prepend header with field names if first line does'nt contain it already
fputs($new, flat_a2csv($fla,1));
}
}
if (($dupe == 'update' || $dupe == 'ignore')
&& isset($dedupe_num)
&& $flb["{$dedupe_num}"] == $fla["{$dedupe_num}"]["{$prefix}[{$dedupe}]"]) {
$dupe_found = 1;
if ($dupe=='update') {
continue;
}
}
fputcsv($new, $flb);
$i++; // Increment line counter
}
if (($dupe_found == 1 && $dupe == 'update') || $dupe == 'append' || !isset($dedupe_num)) {
// Update dupe or append
fputs($new, flat_a2csv($fla));
}
@fclose($old); // Releases lock automatically
@unlink($datadir.'/'.$csvname); // Delete old csv data file
fclose($new);
rename($datadir.'/'.$csvname.'.new', $datadir.'/'.$csvname);
if (is_file($exitpage) && is_readable($exitpage)) {
include($exitpage);
exit;
} else {
?>
<title>form2csv</title>
Form data logged - Thx for your submission!
<?php
exit;
}
?>
wenn ich die datei auf dem server öffne, sagt der browser mir folgende fehlermeldung:
Fatal error: Cannot redeclare fputcsv() in /usr/export/www/vhosts/funnetwork/hosting/...homepageadresse.../form2csv1.php on line 203
PHP:
zeile 174 // Based on a function posted on [url]http://php.net/manual/de/function.fgetcsv.php[/url]
function fputcsv ($fp, $array, $deliminator=',', $enclosure='"') {
$alwaysenc = 1; // Always add enclosure
$line = '';
foreach($array as $val) {
// remove any windows new lines,
// as they interfere with the parsing at the other end
$val = str_replace("\r\n", "\n", $val);
if ($alwaysenc) {
$line .= $enclosure.addslashes($val).$enclosure.$deliminator;
} else {
// if a deliminator char, a double quote char or a newline
// are in the field, add quotes
if (ereg("[$deliminator\"\n\r]", $val)) {
$val = $enclosure.str_replace($enclosure, $enclosure.$enclosure, $val).$enclosure;
}
$line .= $val.$deliminator;
}
}
// strip the last deliminator
$line = substr($line, 0, (strlen($deliminator) * -1));
$line .= "\n";
// we don't care if the file pointer is invalid,
// let fputs take care of it
return fputs($fp, $line);
}
// we don't care if the file pointer is invalid,
// let fputs take care of it
return fputs($fp, $line);
zeile 203 }
Da ich mich damit gar nich auskenn, frag ich euch
