在没有 $_FILES 的情况下在 PHP 中操作文件
我正在尝试以编程方式为图像添加色调。我已经使用表单和 $_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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在以下代码中,您将 $_FILES 数组结构传递给 Upload 类:
变量
$_FILES['imgfile']
本身是一个数组,由命名成员组成,例如'name '
、'tmp_name'
等 - 接收上传文件的服务器已传递给 PHP 的文件信息。您的
Upload
类似乎是为处理这种结构而设计的。它可能是专门为处理文件上传而设计的,因此您可能需要对其进行一些修改,以允许将任何文件路径作为参数而不是此数组结构传递给它。In the following code, you are passing a $_FILES array structure to your Upload class:
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.好吧,你可以伪造 $_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.