The idea is to create a table with a unicoid field.
A page that will insert $key = uniqid(md5(Rand())); in the unicoid field and generate a download link.php? id=". $key
On the download page get the database key equal to the value of the id parameter. If it exists, force the browser to download and immediately delete the unicoid field.
downloadkey.php
$link = new mysqli ("localhost", "USUARIO", "SENHA", "DB");
if(empty($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
}
$url = preg_replace('/\?.*$/', '', $_SERVER['REQUEST_URI']);
$folderpath = 'http://'.$_SERVER['HTTP_HOST'].'/'.ltrim(dirname($url), '/').'/';
$key = uniqid(md5(rand()));
$time = date('U');
echo "<p>Download link: <a href=\"" . $folderpath . "download.php?id=" . $key . "\">Baixar</a></p>";
echo "<p><span class=\"box\">" . $folderpath . "download.php?id=" . $key . "</span></p>";
$sqli = ("INSERT INTO downloadkey (uniqueid,timestamp) VALUES(\"$key\",\"$time\")");
$result= mysqli_query($link,$sqli);
mysqli_close($link);
Download.php
$link = new mysqli ("localhost", "USUARIO", "SENHA", "DB");
if (!$link) {
die("Connection failed: " . mysqli_connect_error());
}
$query = ("SELECT * FROM downloadkey Where uniqueid='".$_GET['id']."'");
$result = mysqli_query($link,$query);
if (mysqli_num_rows($result) > 0) {
$arquivo = 'arquivo.zip';
header('Content-type: octet/stream');
header('Content-disposition: attachment; filename="'.$arquivo.'";');
readfile($arquivo);
$sql = ("DELETE FROM downloadkey Where uniqueid='".$_GET['id']."'");
$result = mysqli_query($link,$sql);
exit;
}else{
echo "<p>Link de download que você está usando é inválido.";
echo "<br><a href=\"downloadkey.php\">Clique aqui para obter novo link de download</a></p>";
}
mysqli_close($link);
So it is, your question is wide, can you put the code you have ? You have an understanding in PHP or Javascript ?
– MagicHat
Even then because I don’t know much about PHP or js, I thought there was a code or plugin that we just use the file or paste a url and that’s it
– Márcio Sebastião
Well I don’t know, maybe someone with more WP experience will show you 1, good luck.
– MagicHat
Marcio, the site is only about programming even, plugin indication does not fit in site scope. But even if you close the issue out of scope, comments remain open if someone has a tip to give you. If you try to learn the basics to do something and have questions, I think the site will be more useful to help you.
– Bacco
In fact, I believe that it should not even be necessary an advanced level to solve your problem, maybe if you find in the code, the html related to this button and edit your question, passing more information you can save... is that it is a bit confusing what you are trying to do, at least I’m not understanding... maybe an example..
– MagicHat
Using DB you get your intent!
– user60252
DB would be the Dropbox? If it is not the
– Márcio Sebastião
That’s what I’m looking for, I’ll learn php
– Márcio Sebastião
@Leocaracciolo why don’t you put this as an answer ? It seems to answer the question well... So other users like similar doubt could benefit...
– MagicHat
ok I will post the codes in the reply
– user60252