Grazie mille Cavicchiandrea. Ho letto alcuni degli esempi ma sono scritti tutti in php non procedurale così faccio un po' fatica a comprenderlo. Per ora ho letto 1 solo libro di php così sono ancora molto impedito ma con qualche dritta forse posso riuscire a fare questo script.
Ho trovato un esempio che credo sia perfetto per il mio caso ma ha un problema di fondo: salva il file nel database. Pensavo di correggere questo script ma non so come scrivere in php "copia il file in DOWNLOADDIRECTORY e copia un url nel database".
Il punto dove intervenire è certamente questo:
Codice PHP:
<?php
include_once $_SERVER['DOCUMENT_ROOT'] .
'/includes/magicquotes.inc.php';
if (isset($_POST['action']) and $_POST['action'] == 'upload')
{
// Bail out if the file isn't really an upload
if (!is_uploaded_file($_FILES['upload']['tmp_name']))
{
$error = 'There was no file uploaded!';
include $_SERVER['DOCUMENT_ROOT'] . '/includes/error.html.php';
exit();
}
$uploadfile = $_FILES['upload']['tmp_name'];
$uploadname = $_FILES['upload']['name'];
$uploadtype = $_FILES['upload']['type'];
$uploaddesc = $_POST['desc'];
$uploaddata = file_get_contents($uploadfile);
include 'db.inc.php';
try
{
$sql = 'INSERT INTO filestore SET
filename = :filename,
mimetype = :mimetype,
description = :description,
filedata = :filedata';
$s = $pdo->prepare($sql);
$s->bindValue(':filename', $uploadname);
$s->bindValue(':mimetype', $uploadtype);
$s->bindValue(':description', $uploaddesc);
$s->bindValue(':filedata', $uploaddata);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Database error storing file!';
include $_SERVER['DOCUMENT_ROOT'] . '/includes/error.html.php';
exit();
}
header('Location: .');
exit();
}