
如何将上传的文件从 input file 中拷贝到其他位置?
想要将上传的文件从 input file 中拷贝到其他位置,需要遵循以下步骤:
<form action="xx.php" method="post" enctype="multipart/form-data"> <input type="file" name="pic" accept="image/*" id="file" /> <input type="submit" name="btn" /> </form>
<?php
if (isset($_FILES['pic'])) {
// 获取文件的临时存储路径
$tmpPath = $_FILES['pic']['tmp_name'];
// 指定要拷贝到的新路径
$newPath = "./1.jpg";
// 使用 move_uploaded_file() 函数拷贝文件
if (move_uploaded_file($tmpPath, $newPath)) {
// 文件拷贝成功
} else {
// 文件拷贝失败
}
}
?>需要注意的是,在 php 文件中指定的新路径必须具有可写权限。
以上就是如何用PHP将上传文件从Input File控件复制到指定位置?的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号