Uploads and Downloads
Hey guys me again ,
This have a big problem with the downloads of my file:
I created an upload system for my mp3 the name of the file is created by the function witch
Moves my files ti the server. I can see the file with the correcte extention in my folders but when I use the download script, then things sukcs.
This is my upload script:
<?php
if ($_FILES['track']['error'] > 0) $erreur = "Erreur lors du transfert";
$extensions_valides = array( 'mp3' , 'mid','wma' );
$extension_upload = strtolower( substr( strrchr($_FILES['track']['name'], '.') ,1) );
if ( in_array($extension_upload,$extensions_valides) ) echo "Extension correcte";
$nomtrack = md5(uniqid(rand(), true));// create a unique name 4 da file
$nom = "musiques/{$nomtrack}.{$extension_upload}";
$resultat = move_uploaded_file($_FILES['track']['tmp_name'],$nom);
if ($resultat)
{
echo "Transfert ok";
}
Else
{
Echo 'transfet failed';
}
}
//-------------------------------------
// insert in the database
$query = $db->prepare('INSERT INTO chansons (album_id, chanson_titre, chanson_lien)
VALUES ( :albumid, :titres, :nom)');
$query->execute(array(
'albumid' => $albumid,
'titres' => $titres,
'nom' => $nom));// the path and name of the file uploaded
$query->closeCursor();
?>
It works this script
This is the probleme whe I use the down load script bellow:
<?php
$fichier=$_GET['nom'];$ext="mid";header('Content-disposition: attachment; filename=$fichier');
header('Content-type: audio/mid');
readfile('$fichier.$ext');
?>
It forces the download with the file name but no extentions on the file and all files are 2Kb.
Don't know where I went wrong! Need help
Greg K posted this at 02:45 — 3rd November 2011.
He has: 2,145 posts
Joined: Nov 2003
Well from the readfile line, I'm assuming that $fichier does NOT contain the extention on the file, so on the header() function, you are not giving it an extention.
Additionally, on the readfile() function, you are wrapping it with single quotes, which will not parse variables within it, so no matter what, it will always look for a file names (literally) $fichier.$ext, not whatever those variables hold. (need double quotes for that).
My guess why all of them are 2kb is that if you actually opened the files in a text editor, they are probably actually errors from the server saying it cannot find the file specified.
-Greg
Dj@n posted this at 07:42 — 8th November 2011.
They have: 4 posts
Joined: Oct 2011
Thnx guys, will check it out and let u know what!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.