PHP 保存/存储文件到远程服务器?

发布于 2025-01-01 19:59:18 字数 92 浏览 2 评论 0原文

用户是否可以在不使用 FTP 而是使用 Web 界面 (php) 的情况下将照片和视频保存/存储到远程服务器,而不是本地主机?

如果可以的话,该怎么办呢?

Is it possible for users to save / store their photos and videos to remote server, not localhost without using FTP but using web interface (php)?

If so, how to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

a√萤火虫的光℡ 2025-01-08 19:59:18

设置一个新表单:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
Choose a file to upload: <input name="file" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

在 uploader.php 中,您应该有类似以下内容:

$folder = "uploads/";

$path = $folder . basename( $_FILES['file']['name']); 

if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
    echo "The file ".  basename( $_FILES['file']['name']). " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

这是将文件上传到服务器的最简单方法之一。但是,您可能想要自定义并向文件上传表单添加更多信息。

Set a new form:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
Choose a file to upload: <input name="file" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

In uploader.php you should have someting like:

$folder = "uploads/";

$path = $folder . basename( $_FILES['file']['name']); 

if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
    echo "The file ".  basename( $_FILES['file']['name']). " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

This is one of the simplest methods to upload a file to a server. However you might want to customize and add some more information to your file upload form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文