Hello guys!!
I really need help with this one. The principal idea is to download files, for the moment any type of files(images, pdf, doc,…)
I almost have the full code (it works. I Upload a file and its show it in the table) however is missing the download part, I know I have to use the header something:
//header(‘Content-Disposition: attachment; filename=’. basename($folder));
//readfile($folder);
but where and how I have to do it that I dont know.
thanks.
This is the first part html file.
<!doctype html>
<html>
<head>
<title>...</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/$$$.css">
<script src="js/.js"></script>
</head>
<body>
<h1>Files</h1>
<form action="files.php" method="post" enctype="multipart/form-data">
<input type="file" name="file"></p>
<p>
<input type="submit" value="Upload" />
<input type="hidden" name="submitted" value="TRUE" />
</p>
</form>
</body>
</html>
the second and import part
[php]
$folder=‘file/’;
if( !is_dir($folder) ){
die (“the folder not exits!”);
}
echo “
”;
print_r($_FILES);
echo “
if (isset($_POST[‘submitted’])) {
if (isset($_FILES[‘file’])) {
//if (strpos($_FILES[‘file’][‘type’], “doc”) || strpos($_FILES[‘file’][‘type’], “pdf”) ) {}
//if (in_array($_FILES[‘file’] [‘type’], $allowed)) {
// Move the file over.
if (move_uploaded_file($_FILES[‘file’][‘tmp_name’],
“$folder{$_FILES[‘file’][‘name’]}”)) {
echo ‘
The file has been uploaded!
’;} // End of move… IF.
} else { // Invalid type.
echo '<p class="error">Please upload a pdf or doc file.</p>';
}
} // End of isset($_FILES['upload']) IF.
// Check for an error:
if ($_FILES['file']['error'] > 0) {
echo '<p class="error">The file couldnot be uploaded because: <strong>';
// Print a message based upon the error.
switch ($_FILES['file']['error']) {
case 1:
print 'The file exceeds the upload_max_filesize setting in php.ini.';
break;
case 2:
print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
break;
case 3:
print 'No file was uploaded.';
break;
case 4:
print 'No temporary folder was available.';
break;
default:
print 'A system error occurred.';
break;
} // end of switch
print '</strong></p>';
} // End of error IF.
if (file_exists
($_FILES['file']['tmp_name']) &&
is_file($_FILES['file']['tmp_name']) ) {
unlink
($_FILES['file']['tmp_name']);
}
// } // End of the submitted conditional.
?>
Name | link |
---|---|
$arc | Download |
[/php]