Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("UPLOAD_DIR", "/var/www/lifecycle/tmp");
- if (!empty($_FILES["usrFile"])) {
- $usrFile = $_FILES["usrFile"];
- //check for errors
- if ($usrFile["error"] !== UPLOAD_ERR_OK) {
- echo "<p>An error occurred.</p>";
- exit;
- }
- // ensure a safe filename
- $name = preg_replace("/[^A-Z0-9._-]/i", "_", $usrFile["name"]);
- print_r($name."<br>");
- // don't overwrite an existing file
- $i = 0;
- $parts = pathinfo($name);
- while (file_exists(UPLOAD_DIR . $name)) {
- $i++;
- $name = $parts["filename"] . "-" . $i . "." . $parts["extension"];
- }
- print_r("new name: ".$name."<br>");
- lstat(UPLOAD_DIR);
- // preserve file from temporary directory
- $success = move_uploaded_file($usrFile["tmp_name"],
- UPLOAD_DIR . $name);
- if (!$success) {
- echo "<p>Unable to save file.</p>";
- exit;
- }
- // set proper permissions on the new file
- chmod(UPLOAD_DIR . $name, 0644);
- //check that the file is not executable (doesn't work)
- $ftype = array();
- //exec("file " . UPLOAD_DIR . $name, ftype); <- returns a 500 error
- print_r(ftype);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement