在没有 $_FILES 的情况下在 PHP 中操作文件

发布于 2024-12-12 23:50:44 字数 262 浏览 1 评论 0原文

我正在尝试以编程方式为图像添加色调。我已经使用表单和 $_FILES 数组轻松完成了此操作,但我需要从 URL 获取图像,并且我尝试使用的图像位于我自己的服务器上(如果这很重要)。这是工作表单函数的示例代码

$img = new Upload($_FILES['imgfile']);

现在我需要的是类似 $img = new Upload(fopen($image_path); 但这不起作用......请帮助我!

I'm trying to programmatically add a tint to an image. I've done this very easily with a form and the $_FILES array but I need to get the image from a URL, and the images I'm trying to use are on my own server if that is important. Here's a sample code of the working form function

$img = new Upload($_FILES['imgfile']);

Now all I need is something like $img = new Upload(fopen($image_path); But this isn't working... Please help me!!

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

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

发布评论

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

评论(2

原谅我要高飞 2024-12-19 23:50:44

在以下代码中,您将 $_FILES 数组结构传递给 Upload 类:

$img = new Upload($_FILES['imgfile']);

变量 $_FILES['imgfile'] 本身是一个数组,由命名成员组成,例如 'name ''tmp_name' 等 - 接收上传文件的服务器已传递给 PHP 的文件信息。

您的 Upload 类似乎是为处理这种结构而设计的。它可能是专门为处理文件上传而设计的,因此您可能需要对其进行一些修改,以允许将任何文件路径作为参数而不是此数组结构传递给它。

In the following code, you are passing a $_FILES array structure to your Upload class:

$img = new Upload($_FILES['imgfile']);

The variable $_FILES['imgfile'] itself is an array, consisting of named members such as 'name', 'tmp_name' and others - information about the file that has been passed to PHP by the server receiving the uploaded file.

Your Upload class appears to be designed to handle this sort of structure. It will probably have been designed specifically for handling file uploads, so you may need to modify it a bit to allow it to be passed any file path as a parameter instead of this array structure.

莳間冲淡了誓言ζ 2024-12-19 23:50:44

好吧,你可以伪造 $_FILES 数组。
唯一不能欺骗这个数组的函数是 move_uploaded_file() 但看起来你无论如何都不需要它。

但是,你知道,没有人知道你的“新上传”是什么。

Well, you can fake $_FILES array all right.
the only function you cannot fool with this array is move_uploaded_file() but it seems you don't need it anyway.

but, you know, nobody have an idea what your "new Upload" is.

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