i know that
$localfile = $_FILES['media']['tmp_name'];
will get the image given that the POST method was used. I am trying to read an image which is in the same directory as my code. How do i read it and assign it to a variable like the one above?
If you want to read an image and then render it as an image
If your path is a url, and it is using https:// protocol then you might want to change the protocol to http
Working fiddle
The code you posted will not read the image data, but rather its filename. If you need to retrieve an image in the same directory, you can retrieve its contents with
file_get_contents()
, which can be used to directly output it to the browser:Otherwise, you can use the GD library to read in the image data for further image processing:
Finally, if you don't know the filename of the image you need (though if it's in the same location as your code, you should), you can use a
glob()
to find all the jpegs, for example: