PHP/Form/is uploaded file — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 07:04, 26 мая 2010
Checking for the existence of an uploaded file
<?php
if (!is_uploaded_file($HTTP_POST_FILES["upload_file"]["tmp_name"])) {
$error = "You must upload a file!";
unlink($HTTP_POST_FILES["upload_file"]["tmp_name"]);
}
else {
}
?>
Uploading a file
<?php if ($_SERVER["REQUEST_METHOD"] == "GET") { ?>
<form method="post" action="<?php echo $_SERVER["SCRIPT_NAME"] ?>"
enctype="multipart/form-data">
<input type="file" name="document"/>
<input type="submit" value="Send File"/>
</form>
<?php } else {
if (isset($_FILES["document"]) &&
($_FILES["document"]["error"] == UPLOAD_ERR_OK)) {
$newPath = "/tmp/" . basename($_FILES["document"]["name"]);
if (move_uploaded_file($_FILES["document"]["tmp_name"], $newPath)) {
print "File saved in $newPath";
} else {
print "Couldn"t move file to $newPath";
}
} else {
print "No valid file uploaded.";
}
}
?>