开发者

Moving form $_FILES to $_GET

开发者 https://www.devze.com 2023-02-11 04:29 出处:网络
I have one old function that I need to edit doSome($_FILES[\'image\']); My ques开发者_运维技巧tion is how can I use the same function in order to get a file from GET instead of uploading it?

I have one old function that I need to edit

doSome($_FILES['image']);

My ques开发者_运维技巧tion is how can I use the same function in order to get a file from GET instead of uploading it?

If I change to

doSome($_GET['image']);

It doesn't seem to work...


Files uploaded through a form will always end up in PHP's $_FILES superglobal. You can't change that.

You could if you modified PHP's source I suppose.


If you're talking about simply passing a filename to the doSome() function, you could check if the function's argument is an array or not and handle it accordingly.

(Array = from $_FILES, String = NOT from $_FILES)


The faking-it option would be:

doSome( array("tmp_name" => "data:n/a,".$_GET["image"]) );

But in practice you wouldn't want that or should at least create a temporary file and mimick the $_FILES subarray more completely.

And rewriting your old function to accept just the filename or string content would be wiser.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号