I have some code that is supposed to upload a file and move it to the correct folder:
$check = getimagesize($files['image']['tmp_name']);
if($check !== false)
{
$dir = "/var/www/public_html/images/";
$file = $dir.basename($files['image']['name']);
if(file_exists($file))
{
$img = "https://example.com/images/".basename($files['image']['name']);
}
else
{
move_uploaded_file($files['image']['tmp_name'], $file);
$img = "https://example.com/images/".basename($files['image']['name']);
}
}
The issue is that this code is in a function (and a different file), so I cannot directly use $_FILES
. In my other file, where the post occurs, I have this:
Images::editImage($post, $_FILES)
It works for post, but not for files. Is there any way to carry $_FILES
across files?
The statement
The issue is that this code is in a function (and a different file), so I cannot directly use $_FILES.
is false. $_FILES
as a superglobal variable can be used everywhere in a script, class method, function, ...
So, if "... not working" is occurring, the problem might either be that it is not populated due to plainly missing an uploaded file, or access to it's array elements is wrong.