Php文件上载脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Php文件上载脚本相关的知识,希望对你有一定的参考价值。

General file upload script in php. Error set using SESSIONS.
  1. if (!is_dir("directory")) {
  2. mkdir("directory");
  3. }
  4.  
  5. $max_size = 10000; // maximum file size, in KiloBytes
  6. $allowtype = array('pdf'); // allowed extensions
  7.  
  8. if (isset($_FILES['fileToUpload']) && strlen($_FILES['fileToUpload']['name']) > 1) {
  9.  
  10. $file = $ref_id; //Name of file when uploaded
  11.  
  12. $sepext = explode('.', strtolower($_FILES['fileToUpload']['name']));
  13. $type = end($sepext); // gets extension
  14. // Checks if the file has allowed type and size
  15. if (!in_array($type, $allowtype)) {
  16. $_SESSION['status'] = 1;
  17. echo '<script> window.location.href = "redirect.php"; </script>';
  18. }
  19. if ($_FILES['fileToUpload']['size'] > $max_size * 1000) {
  20. $_SESSION['status'] = 2;
  21. echo '<script> window.location.href="redirect.php"; </script>';
  22. }
  23. $uploadpath = 'directory/' . $file; // gets the file name
  24. if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $uploadpath)) {
  25.  
  26. } else {
  27. $_SESSION['status'] = 3;
  28. echo '<script> window.location.href = "redirect.php"; </script>';
  29. }
  30. }

以上是关于Php文件上载脚本的主要内容,如果未能解决你的问题,请参考以下文章

PHP 用于上载ZIP文件并将其解压缩到服务器上的脚本

从HTTP身份验证中排除上载脚本

PHP 使用.htaccess在PHP上载大(大)文件

php文件上载

提高PHP文件上载限制

PHP文件上载