Php 文件\u放置\u内容执行后返回URL

Php 文件\u放置\u内容执行后返回URL,php,Php,我有一组类似这样的函数: <?php //Get the base-64 string from data $filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1); //Decode the string $unencodedData=base64_decode($filteredData); //Save the image file_put_contents('img.png', $unen

我有一组类似这样的函数:

<?php
//Get the base-64 string from data
$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);

//Decode the string
$unencodedData=base64_decode($filteredData);

//Save the image
file_put_contents('img.png', $unencodedData);
?>

这会将名为
img.png
的文件保存到服务器。现在我需要最后一个
file\u put\u contents
函数来返回刚刚创建的文件的路径/绝对URL。我在php文档中似乎找不到这个选项

是否有此选项或任何其他返回路径/绝对URL的方法


如果您正在将脚本写入同一个文件夹,如您的示例所示,请感谢:

dirname($_SERVER['PHP_SELF']) . '/' . 'img.png'
使用:


如果您没有写入web根目录下的目录,则该文件可能没有URL。好吧,假设我将文件设置为写入服务器中的/var/www,我如何“返回”此路径/URL?感谢您的回复,您能告诉我“DIR.”代表什么吗?我在googleDIR上找不到关于它的任何信息,它是php定义的常量。告诉你当前文件目录的绝对路径有可能像这样返回文件的URL吗<代码>http://localhost/img.png,而不是
Library/WebServer/Documents/img.png
实际上我发现,$\u SERVER['SERVER\u NAME']给了我正确的URL路径
      $abs_path = __DIR__.'/img.png';
      file_put_contents($abs_path, $unencodedData);
      echo $abs_path;