Hallo zusammen ich habe versucht aus zwei PHP scripts eines zu machen mit folgendem Ziel. Das Script soll in einem Ordner die aktuellste Datei suchen und diesen Wert bzw. den Dateinamen an eine Datenbank zusammen mit einem Token übergeben für den Filedownload innerhalb von 24 Stunden.
Wenn ich die Seite aufrufe kommt einfach nur: Notice: Array to string conversion in ... Zeile 85 - also dort wo ich den {strKey2} mit übergebe in die Datenbank. Und in der Datenbank steht im entsprechenden Feld einfach nur Array und nicht der Dateiname.
Kann mir hierfür bitte jemand einen Hinweis geben - ich habe wirklich leider absolut keine Ahnung. Vielen lieben Dank
PHP-Code:
<?PHP
$directory = '../otd/downloads';
function lastModification ( $dir, $todo = 'new', $format = 'd.m.Y H:i:s' ) {
if ( is_file ( $dir ) )
return false;
$lastfile = '';
if( strlen( $dir ) - 1 != '\\' || strlen( $dir ) - 1 != '/' )
$dir .= '/';
$handle = @opendir( $dir );
if( !$handle )
return false;
while ( ( $file = readdir( $handle ) ) !== false ) {
if( $file != '.' && $file != '..' && is_file ( $dir.$file ) ) {
if ( $todo == 'old' ) {
if( filemtime( $dir.$file ) <= filemtime( $dir.$lastfile ) ) {
$lastfile = $file;
}
}
else {
if( filemtime( $dir.$file ) >= filemtime( $dir.$lastfile ) ) {
$lastfile = $file;
}
}
if ( empty( $lastfile ) )
$lastfile = $file;
}
}
$strKey2['file'] = $lastfile;
closedir( $handle );
return $strKey2;
}
//connect to the DB
$resDB = mysql_connect("xxx", "xxx", "xxx");
mysql_select_db("xxx", $resDB);
function createKey(){
//create a random key
$strKey = md5(microtime());
//check to make sure this key isnt already in use
$resCheck = mysql_query("SELECT count(*) FROM downloads WHERE downloadkey = '{$strKey}' LIMIT 1");
$arrCheck = mysql_fetch_assoc($resCheck);
if($arrCheck['count(*)']){
//key already in use
return createKey();
}else{
//key is OK
return $strKey;
}
}
//get a unique download key
$strKey = createKey();
//get last file name
$strKey2 = lastModification( $directory );
//insert the download record into the database - Time is: (time()+(60*60*24*7) 60sek X 60min X 24h X 7 Tage = 7 Tage
mysql_query("INSERT INTO downloads (downloadkey, file, expires) VALUES ('{$strKey}', '{$strKey2}', '".(time()+(60*60*24))."')");
?>
<html>
<head>
<title>Printcom One Time Download Token</title>
</head>
<h1>One Time Download</h1>
<p>Ihre unique download URL ist:</p>
<strong><a href="download.php?key=<?=$strKey;?>">download.php?key=<?=$strKey;?></a></strong>
<p>Dieser Link ist 24 h gültig.</p>
</html>
Kann mir hierfür bitte jemand einen Hinweis geben - ich habe wirklich leider absolut keine Ahnung. Vielen lieben Dank
Kommentar