accessing file of another drive

2020-02-16 04:16发布

问题:

previously I could download wav file in php and IIS. But now file is not downloadable.I don't know what is going wrong . After installing and changeing php 5.3 to php 5.4 with php manager in IIS, the file is not able to downloaded. I have link to file to download it which looks like this:

       <a href="download.php?voice='$filename'"> Download </a>

download.php scripts

     <?php
       $filename = $_GET['voice'];
       $dir = 'd:/temp_file/voice/';
       if(is_file($dir.$filename))
        {
          header('Content-type: audio/wav');
          header('Content-Disposition: attachment; filename='".$filename.'"');
          echo file_get_contents($dir.$filename);
       }
      ?>

while I was trying to find the mistake why file is not downloadable, I remove if statement and run program, it does prompt window download file with audio player of empty wav file. So, I conclude that there is mistake in path which is not allowing to access file of another drive. I have php code in c:\inetpub\wwwroot\ but wav file to be download is in the d:\temp_file\voice path. What Should I have to do?

回答1:

Maybe PHP open_basedir restriction.

Try to add d:/temp_file/voice/, to its content in php.ini.

Update

I never used IIS, but another thing that you have to check is if the IIS User have permission to read that directory. Try to add, just for test, Everyone with all permission to d:\temp_file\voice.



回答2:

I don't know what is going wrong

Then enable error reporting, for what it looks like to me it's a syntax error at header('Content-Disposition: attachment; filename='".$filename.'"'), you're missing a quote (') after filename='". But since you say it has worked (and works without the if), I'd say that's a copy paste error.

Then do a var_dump($filename), which might contain quotes, since you put those around the URL in the link (<a href="download.php?voice='$filename'">). The file D:/temp_file/voice/'foo.wav' might not exist.



标签: php iis-7