Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
PDO Insert uploading a textarea into my DB

I have been trying for months to figure out how to fix and create what I am envisioning which I know is possible to be done and probably is not hard to do.

I am trying to take a textarea that I have placed on a page of mine upload its contents into a database where people can view the information they uploaded. Here's an example.

Person A copy/pastes text into a text area at: http://example.com/textarea/ he clicks an upload/submit button and gets a link like this: http://example.com/A93KJUQ21.txt Anyone that has access to that link will be able to click it and it will display the contents that were uploaded to it. Whatever Person A, B, C, D, etc uploads it will generate a new unique link to the information. Example of this would be as follows:

http ://example.com/A93KJUQ21.txt

http ://example.com/JKO2QN498.txt

http ://example.com/PMNR01NEQ.txt

and so on..

Here is the code I currently have

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['upload'])) {
$textarea = $_POST['paste-area'];

//Add validations

$odb = new PDO("mysql:dbname=dbname;host=localhost", "dbusername", 
"mypasswordgoeshere");

$query = $odb->prepare("INSERT INTO submission (`textarea`) VALUES 
(:textarea)"); //I'm just making up the structures

$query->bindParam(':textarea', $textarea, PDO::PARAM_STR);

$status = $query->execute(); //$status contains true or false

//Other codes...
}
}

?>
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Your table needs two columns, the random string and the textarea contents. When the user submits the form, you need to create the random string and insert that into the DB along with the text area.

$string = uniqid();
$query = $db->prepare("INSERT INTO submission (id, textarea) VALUES (:string, :textarea)");
$query->bindParam(':string', $string);
$query->bindParam(':textarea', $textarea);
$query->execute();
echo "Link is <a href='http://example.com/lookup.php?id=$string'>href='http://example.com/lookup.php?id=$string</a>";

I've made the link point to a PHP script. You can't retrieve from the database using a .txt URL, that just tries to download a regular file. You need to point to a PHP script that fetches the textarea from the submission table.

If you want to make it seem like a .txt file, you could use a rewrite rule on the server, that rewrites the .txt URL to the equivalent .php URL.

over 4 years ago · Santiago Trujillo Denunciar

0

why do you think you need a database for this?

<?php
if (!empty($_POST['text'])) {
    $filename = uniqid().".txt";
    file_put_contents($filename, $_POST['text']);
    die("http://".$_SERVER['HTTP_HOST']."/$filename");
}
?>
<form method=post>
<textarea name=text></textarea>
<input type=submit>
</form>
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda