当前位置:Gxlcms > PHP教程 > linux下用PHP实现上传文件到服务器?

linux下用PHP实现上传文件到服务器?

时间:2021-07-01 10:21:17 帮助过:25人阅读

linux 下用PHP实现上传文件到服务器?
服务器软件为apache2
php.ini 中
upload_tmp_dir="/opt/lampp/apache2/htdocs/upload/"

upload 有读写权限
页面显示结果为:
Stored in: /tmp/phppkZB34
tmp同样拥有读写权限

但在tmp中找不到”phppkZB34“这个文件

回复内容:

linux 下用PHP实现上传文件到服务器?
服务器软件为apache2
php.ini 中
upload_tmp_dir="/opt/lampp/apache2/htdocs/upload/"

upload 有读写权限
页面显示结果为:
Stored in: /tmp/phppkZB34
tmp同样拥有读写权限

但在tmp中找不到”phppkZB34“这个文件

上传文件后你需要把 /tmp/phppkZB34 文件(使用move_uploaded_file函数)移动到你自己的目录中,会话结束后 /tmp/phppkZB34 会被删除。函数的使用方式自己去问度娘吧

phpReturn
"; }else if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < (500*1024))) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { echo "Image Details:
    "; echo "
  • Upload: " . $_FILES["file"]["name"] . "
  • "; echo "
  • Type: " . $_FILES["file"]["type"] . "
  • "; echo "
  • Size: " . ($_FILES["file"]["size"] / 1024) . " Kb.
  • "; //echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
    "; if (file_exists("upload/" .date('Ymd_'). $_FILES["file"]["name"])){ echo "
    ".date('Ymd_').$_FILES["file"]["name"]." already exists.
    Fail to Upload.
    "; echo "Click HERE to check."; }else{ move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" .date('Ymd_'). $_FILES["file"]["name"]); echo "
  • Stored in: " . "upload/" .date('Ymd_'). $_FILES["file"]["name"].".
  • "; echo "
  • Permanent Link: ". "upload/" .date('Ymd_'). $_FILES["file"]["name"]."
  • "; echo "
"; } } } else { echo "
Invalid file.
Only png/jpeg/jpg/gif files under 500Kb can be uploaded here.
"; } ?>

我写的,供参考。

人气教程排行