好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php如何设置文件上传路径

php设置文件上传路径的方法:首先创建PHP示例文件;然后修改服务端处理代码;最后通过“move_uploaded_file”移动文件到目标路径即可。

推荐:《PHP视频教程》

PHP文件上传路径

假设上传的文件name值为upload

<input type="file" name="upload" />

服务端处理代码如下:

if(isset($_FILES['upload']) && !$_FILES['upload']['error']) {    // 文件存在且不报错
    $fileName = $_FILES['upload']['name'];   // 获取文件
    $fileExtension = pathinfo($fileName);    // 获取文件路径信息
    $fileExtension = $fileExtension['extension']; // 获取文件后缀
    $time = time(); // 根据时间戳区分
    $destinationPath = "./upload/";  // 目标文件夹
    $newFileName = $destinationPath.$time.".".$fileExtension;    // 完整的url
    if(move_uploaded_file($_FILES['upload']['tmp_name'], $newFileName)) {  // 移动文件到目标路径
   echo("文件移动成功");
    } else {
   die("文件路径出错");
    }
 
}

以上就是php如何设置文件上传路径的详细内容!

查看更多关于php如何设置文件上传路径的详细内容...

  阅读:59次