note 123920 added to reserved.variables.files
| From: | poppygloria@php.net | Date: | Sun, 09 Jun 2019 17:11:36 +0000 |
| Subject: | note 123920 added to reserved.variables.files | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-211201@lists.php.net to get a copy of this message | ||
For uploading only one file, my version, that checks if the file is uploaded.
function processForm($messages) {
if ($_FILES['file']["error"] == UPLOAD_ERR_OK ) {
if($_FILES['file']['type'] != "text/csv" &&
$_FILES['file']['type'] != "application/vnd.ms-excel") {
$messages->add_error('Wrong format.');
return false;
}
elseif ( !move_uploaded_file( $_FILES['file']["tmp_name"], "files/" .
basename( $_FILES['file']["name"] ) ) ) {
$messages->add_error('Upload failed');
return false;
}
}
else {
$messages->add_error("Something went wrong.");
return false;
}
return true;
}
if (isset($_POST['btnUpload'])) {
if(is_uploaded_file($_FILES['file']['tmp_name'])) {
if (processForm($messages)) {
$fileName = "files/" . basename($_FILES['file']['name']);
parseAndInsert($fileName, $db);
$messages->add_message("Success");
}
}
else {
$messages->add_error('File did not upload');
}
}
function parseAndInsert($fileName, $db) {
$file = fopen($fileName, "r");
while($line = fgetcsv($file, 1000, ";")) {
$db->addGrade(intval($line[0]), intval($line[1]), intval($line[2]));
}
fclose($file);
}
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.195 (proxied: 24.135.240.64)
----
Manual Page -- http://php.net/manual/en/reserved.variables.files.php
Edit -- https://master.php.net/note/edit/123920
Del: integrated -- https://master.php.net/note/delete/123920/integrated
Del: useless -- https://master.php.net/note/delete/123920/useless
Del: bad code -- https://master.php.net/note/delete/123920/bad+code
Del: spam -- https://master.php.net/note/delete/123920/spam
Del: non-english -- https://master.php.net/note/delete/123920/non-english
Del: in docs -- https://master.php.net/note/delete/123920/in+docs
Del: other reasons-- https://master.php.net/note/delete/123920
Reject -- https://master.php.net/note/reject/123920
Search -- https://master.php.net/manage/user-notes.php