PHP: File cannot be downloaded ("404 Not Found" message) -


i working on website of client didn't write code. have troubles making files downloadable.

it subdomain users can download course files. website files contained in folder "courses" (on root level).

  • the file displaying downloadable course files contained in "courses/displayfiles.php".
  • the downloadable files contained in folder in "courses/downloadfolder". inside folder, each user has own files folder name has user id.

displayfiles.php: following code displays files can downloaded logged-in user:

  $path = "downloadfolder/" . $_session['userid'] . "/";   $files = array();   $output = @opendir($path) or die("$path not found");    while ($file = readdir($output)) {     if (($file != "..") , ($file != ".")) {       array_push($files, $file);     }   }   closedir($output);   sort($files);    foreach ($files $file) {     echo '<a class="imtext" href="downloadfolder/' . $_session['userid'] . '/' . $file . '/">' . $file . '</a><br/>';   } 

so not work code: when user clicks on file, "404 not found" message file not found. how can be?

why displaying files totally works fine, @ same time 404 error when clicking file? files path ($path) must correct, or not? further investigations need take in order solve problem?

* update *

i decided modify files loop followed (changing href):

foreach ($files $file) {             echo '<a class="imtext" href="http://'.$_server['http_host']. '/downloadfolder/' . $_session['courseid'] . '/' . $file . '/">' . $file . '</a><br/>';       } 

still, when click on file, 404 not found error. how can be?

you have webroot of page is, php file generating list located , wherer files are.

your generated link relative php file generating link, might not corresponding url in browser. i'd try make link relative webroot (note leading slash!)

echo '<a class="imtext" href="/courses/downloadfolder/' . $_session['userid'] . '/' . $file . '/">' . $file . '</a><br/>'; 

if guessed solution doesn't work please provide current url of page links generated , 1 generated link, can better.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -