this somewhat relates to an older topic i made last week.
basically i was trying to figure out why the download script i was using kept causing the file to get mess up(kept making random symbols and junk)
after several tests i found the error, the define constants im using for my mysql login details doesnt seem to go well with the download script.
basically i added the define on the download page, this caused no problems at all. but when i included the file that had the exact same define values it caused errors.
so my question is, how can i prevent/fix this?
i've been trying to fix this for a while now, and whoever helps me will really be doing me a fat one
You would need to post the relevant code so that someone could examine it for the problem and/or duplicate the problem.
I suspect that you wrote an indexed variable like this - $_POST[someindex] or $_FILES[someindex] (not making the index name a quoted string) and someindex is also a defined constant and PHP used that instead of what you intended.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
#see if any important ids are left blank. if(empty($id)){ #send that user to the index page. header("Location: index.php"); } // Check to see if the download script was called if (basename($_SERVER['PHP_SELF']) == 'downloader.php'){ #see if attachment is listed, if so proceed. $q = mysql_query("select Filename from ebb_attachments where id='$id'"); $attach_ct = mysql_num_rows($q); $attach_r = mysql_fetch_assoc($q);
# $db->run = "select Filename from ebb_attachments where id='$id'"; # $attach_ct = $db->num_results(); # $attach_r = $db->result(); # $db->close();
if ($attach_ct == 1){ #check if the file exists, if it doesn't, fire an error message and kill the script $file = str_replace('%20', ' ', $attach_r['Filename']); $dl_path = "uploads/".$file; #see if the user is trying to access another directory. if (substr($file, 0, 1) == '.' || strpos($file, '..') > 0 || substr($file, 0, 1) == '/' || strpos($file, '/') > 0){ #Display hack attempt error die("Hack attempt detected!"); } #see if the file exists. if(!file_exists($dl_path)){ echo "404"; } $ext = strtolower(substr(strrchr($file, "."), 1)); #Determine correct MIME type switch($ext){ case "asf": $type = "video/x-ms-asf"; break; case "avi": $type = "video/x-msvideo"; break; case "exe": $type = "application/octet-stream"; break; case "mov": $type = "video/quicktime"; break; case "mp3": $type = "audio/mpeg"; break; case "mpg": $type = "video/mpeg"; break; case "mpeg": $type = "video/mpeg"; break; case "rar": $type = "encoding/x-compress"; break; case "txt": $type = "text/plain"; break; case "wav": $type = "audio/wav"; break; case "wma": $type = "audio/x-ms-wma"; break; case "wmv": $type = "video/x-ms-wmv"; break; case "zip": $type = "application/x-zip-compressed"; break; default: $type = "application/force-download"; break; } #Fix IE bug. $header_file = (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ? preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1) : $file; header("Pragma: public"); #required.
header("Cache-Control: private",false); #some browsers require this
header("Content-Type: $type"); #declares file as an attachment. header("Content-Disposition: attachment; filename=\"" . $header_file . "\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($dl_path));
#Send file for download if ($stream = fopen($dl_path, 'rb')){ while(!feof($stream) && connection_status() == 0){ #reset time limit for big files set_time_limit(0); print(fread($stream,1024*8)); flush(); } fclose($stream); } }else{ #display an error here. echo "ERROR!"; } } ob_end_flush(); ?>
i snipped out the include function since it was what i already ruled out. i have confirmed the download script is not to blame.
basically in a nutshell, if i have to remove the define() functions, i would like to use a method that would be just as secure as thats a top priority for this application.
This is just a guess since you did not post it, but the include file probably contains PHP syntax errors or the include(...) function call was failing due to a path/file name problem. X-out the sensitive information in your code, but post the actual file so that the syntax and defined constant names can be seen.
You did mention errors, what exactly are they???
We cannot help you without "seeing" the same information you have about the problem. The only way we can see what you see is if you post it or describe it accurately.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
by errors i mean the files get messed up to the point that they dont open or if they you just get a bunch of rubbish.
this is what config has in it:
PHP Code:
if (!defined('IN_EBB') ) { die('<b>!!ACCESS DENIED HACKER!!</b>'); }
// Database Connection Settings.
define("DB_HOST", "localhost"); //usually this is localhost if it isnt ask your provider define("DB_NAME", "xxxxxxx"); //Name of your Database define("DB_USER", "xxxxxxx"); //Username of Database define("DB_PASS", "xxxxxxx"); //Password of database
//password encryption salt. This was created for you during the install. DO NOT ALTER THE VALUE!! define("PWDSALT", "xxxxxxxxxxxx");
but heres the kicker, i add this to the download file directly, no problems at all
now i would just add the connection string to the download file if i was the only one using this, but this is a script that anyone will be able to use so i cant go that route.
Any PHP opening and closing tags <?php ... ?> at the beginning and end in that file, or did you just omit them in the post?
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
by errors i mean the files get messed up to the point that they dont open or if they you just get a bunch of rubbish.
What kind of rubbish? maybe there's something wrong with the headers you set, so the file is displayed instead of downloaded?
Is the setting "display_errors" turned on? and what's the level of error_reporting. To debug your script add the following lines on top of your code (if not allready set like that in the ini file):
Have you tried not using the buffered output? Having read your problem, it seems mostly like to be something got messed up when file is being dumped in the output stream.
Also I suggest you check on your server if its not your file that's corrupt, and take out some headers like Content-Transfer-Encoding.