Re: File upload problem
| From: | Blake Schroeder | Date: | Thu, 18 Dec 2003 19:48:50 +0000 |
| Subject: | Re: File upload problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-172969@lists.php.net to get a copy of this message | ||
This works for me
My Form
<?php
?>
<form enctype="multipart/form-data" action="savefile.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
Send this file: <input name="filename" type="file">
<input type="submit" value="Send File">
</form>
savefile.php
<?php
// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of
// $_FILES. In PHP earlier then 4.0.3, use copy() and is_uploaded_file()
// instead of move_uploaded_file
$uploaddir = '/fullDirectoryPath';
$uploadfile = $uploaddir. $_FILES['filename']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['filename']['tmp_name'], $uploadfile)) {
print "File is valid, and was successfully uploaded. ";
print "Here's some more debugging info:\n";
print_r($_FILES);
} else {
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
print "</pre>";
?>
Dino Costantini wrote:
i'm trying to write a page which allows user to upload file. theese are my sources but they didn't work, anyone could help me? -----form.html-------- <form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="upfile"> <input type="hidden" name="MAX_FILE_SIZE" value="10000"> <input type="submit" value="Invia il file"> </form> --------upload.php----------- <?php // QUESTE RIGHE RENDONO LO SCRIPT COMPATIBILE CON LE VERSIONI // DI PHP PRECEDENTI ALLA 4.1.0 if(!isset($_FILES)) $_FILES = $HTTP_POST_FILES; if(!isset($_SERVER)) $_SERVER = $HTTP_SERVER_VARS; /********************* VARIABILI DA SETTARE ********************/ // Directory dove salvare i files Uploadati ( chmod 777, percorso assoluto) $upload_dir = $_SERVER["DOCUMENT_ROOT"] . "/esempi"; // Eventuale nuovo nome da dare al file uploadato $new_name = "ciao.dino"; // Se $new_name è vuota, il nome sarà lo stesso del file uploadato $file_name = ($new_name) ? $new_name : $_FILES["upfile"]["name"]; if(trim($_FILES["upfile"]["name"]) == "") { die("Non hai indicato il file da uploadare !"); } if(@is_uploaded_file($_FILES["upfile"]["tmp_name"])) { @move_uploaded_file($_FILES["upfile"]["tmp_name"], "$upload_dir/$file_name") or die("Impossibile spostare il file, controlla l'esistenza o i permessi della directory dove fare l'upload."); } else { die("Problemi nell'upload del file " . $_FILES["upfile"]["name"]); } echo "L'upload del file " . $_FILES["upfile"]["name"] . " è avvenuto correttamente"; ?> ----------------------- upload.php doesn't upload anything and doesn't output any error message. i don't think it's an apache problem, because this is the only page that doesn't work.-- +-----------------+-----------------+----------------+ | Blake Schroeder | Owner/Developer | lhwd.net | +--(http://www.lhwd.net)------------+--/3174026352\--+