In my PHP script I have a line that reads a file with fopen
, using url "https://api.modarchive.org/downloads.php?moduleid=".$i
( $i
is a counter of a loop ) where I save the file in I want to save it to my computer using $file
, but for this, I need to define the path which I want to save, including the file extension.
The problem is that you can not know the file extension just downloaded by the URL, so you can not use file_put_contents()
, nor pathinfo()
, nor any type of function that uses the file path as parameter, I can actually downloading the file, but setting a default extension, or not setting.
The problem is that the original files have extensions and types that vary.
The code I'm currently trying to run is this:
for($i = 1; $i < 5; $i ++){
$file = fopen("https://api.modarchive.org/downloads.php?moduleid=".$i, 'r');
file_put_contents("mods/mod".$i.".extensaodoarquivo", $file);
}
Is there a function that returns the file name or file extension, perhaps by passing the file itself instead of a string representing its path, or some better solution?
>