php using "Content-Disposition:attachment; and Content-type:application/octet stream, gives "/n" - header

$file_name="test.key"; $key="1111111";
header("Content-disposition: attachment; filename=$file_name");
header("Content-type: application/octet-stream"); echo trim($key);
the above listed is my piece of code but when this is called, when opening the document, I am having to new lines before "11111111".
May I know, how to avoid new line space, is this an issue or am I using wrong headers,
Here the scenario is I'll get the key from the database and give that key as a download option.
Thanks in advance

Related

How to create and set content type in Vcard generate file in PHP

I have been working to generate vcard file in php just simple way.
my code like following :
header('Content-Type: text/x-vcard;charset=utf-8;');
header('Content-Disposition: inline; filename= "'.$file.'"');
header("Pragma: no-cache");
and generated file is something like this:
BEGIN:VCARD
FN:Elke Schöne;
ADR;INTL;HOME:;;;Leipziger Straße 3;Markranstädt;04420;
EMAIL;INTERNET:praxis.elkeschoene#t-online.de
TEL;FAX;HOME:+49 34205 83980
TEL;HOME:+49 34205 88249
URL;WORK:www.praxis-schoene.de
REV:20161207
END:VCARD
But when i open this file in Windows Contact then name "Schöne" is not encoded and display with special character, but it works fine in Thunderbird contact.
can anybody help me..
You can add the charset:
FN;CHARSET=Windows-1252:Elke Schöne
The semi colon at the end of the lines is not needed on vcard.

SoapUI Auth Header with special characters

I am using SoapUI and encountered that if I add umlauts into the password, it does not work as expected.
Here is an example: Lets assume as username "täst" and as password "!23Öüok". SoapUI will create the following Base64 encoded String: "Authorization: Basic dD9zdDohMjM/P29r[\r][\n]". Decoding "dD9zdDohMjM/P29r" will result into this "t?st:!23??ok".
Is there any SoapUI specific setting or anything that I am missing? I think the Base64 encoded String should be like this: "dMOkc3Q6ITIzw5bDvG9r"
I believe that you need to have have encoding as UTF-8 in order to see the desired value.
Go to SOAPUI_HOME/bin
Have a backup of soapui.bat file
Close soapui tool if it is running
Open soapui.bat in a text editor of your choice
Find line set JAVA_OPTS=%JAVA_OPTS% -Dsoapui.ext.libraries="%SOAPUI_HOME%ext"
Add below line after the above line
set JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF-8
Save the file
Restart soapui, make sure that is reflected in System Properties
This should help you to see the desired output.
Note that if you are using testrunner.bat to execute the tests, incorporate the above suggested change into this file as well.

MSDN Microsoft Translator API

I used the PHP script exactly from MSDN (with my own Id) and it works fine (urlencoding my text!). I can hear my text!
So far, I'm happy, but... the script overwrites my own page, leaving just a tab for playing the text.
How can I capture the response in an mp3 file, from within this PHP script?
Hope someone can help me out!
Meantime it's OK:
I removed
header('Content-Type: audio/mp3');
And put in place
$mp3 = $translatorObj->curlRequest($url, $authHeader);
$file = md5($text); // random name
$file = "audio/" . $file . ".mp3";
file_put_contents($file, $mp3);

I encounter an error while i trying to redirect from one page to another in my demo site page

What this actually means?
I dont understand the error. Please help me
Warning: Cannot modify header information - headers already sent by (output started at /home/mksdemo/public_html/Admin/login.php:31) in /home/mksdemo/public_html/Admin/login.php on line 84
on line no 31 only
This means you have added some echo statement before making the redirect . You should change the location and do the exit from the script and it should be done in the beginning itself
You are trying to do your redirect using the header() function, however, according to HTTP protocol, all headers have to be issued before any content is sent (using something like echo, print(), or even a closing ?> tag). It sounds like you are calling header() in
login.php on line 84
and you have something sending content in
login.php on line 31
You should make sure the header is being sent before this and all other possible lines of output.

Adobe reader online doesn't read all pdf?

As the title says i made a script to read pdf files. Only specifical files can be opened. All files last modified till 29-09-2008 can be opened. All files after can't.
Here is my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Stienser Omroeper</title>
</head>
<body>
<?php
$file = 'E:/Omrop/'.$_GET['y'].'/'.$_GET['f'];
$filename = $_GET['f'];
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
#readfile($file);
?>
</body>
</html>
The $_GET contains y (year for map structure) and f (the filename). If i echo $file after and use the link in run on my pc it works perfectly. In browser i get the message This file is broken and can't be repaired..
Anybody ideas?
This code contains a filesystem traversal vulnerability. You are performing no validation of the arguments that lead to the file. Files on disk are blindly opened and fed to the client.
What if you were on a Unix system? What would happen if someone submitted ?y=&f=../../../etc/passwd?
That doesn't even touch the fact that you aren't doing any sort of sanitization on the user's desired filename for the file. The user could submit entirely bogus data there and get an entirely bogus filename.
This code performs no error checking, and even expressly turns errors off when throwing the file at the user using readfile. This is the root of your problem. Nobody has any idea what's going wrong.
So, we can fix this.
First things first, you're going to want to do some validation on y and f. You mentioned that y is a year, so
$year = (int)$_GET['y'];
should do the trick. By forcing it into an integer, you remove any horibleness there.
f is going to be a bit more tricky. You haven't given us an idea about what the files are named. You're going to want to add some pattern matching validation to ensure that only valid filenames are looked for. For example, if all the PDFs are named "report_something_0000.pdf", then you'd want to validate against, say
$file = null;
if(preg_match('/^report_something_\d{4}\.pdf$/', $_GET['f'])) {
$file = $_GET['f'];
}
Now that we've got a valid filename and a valid year directory, the next step is making sure the file exists.
$path = 'E:/Omrop/' . $year . '/' . $file;
if(!$file || !file_exists($path) || !is_readable($path)) {
header('HTTP/1.0 404 File Not Found', true, 404);
header('Content-type: text/html');
echo "<h1>404 File Not Found</h1>";
exit;
}
If $file ended up not being set because the pattern match failed, or if the resulting file path wasn't found, then the script will bail with an error message.
I'm going to guess that your problems opening older PDFs are caused by the files not existing or having bad permissions. You're feeding Adobe Reader the right headers and then no data.
You'll also want to perform the same kind of sanity checking on the user-supplied desired filename. Again, I don't know your requirements here, but make sure that nothing bogus can sneak in.
Next, get rid of the # in front of readfile. It's suppressing any actual errors, and you're going to want to see them. Because you probably don't want to see them in the output, make sure to set up an error log instead.
Finally... how is this code even working? You're emitting headers in the middle of HTML! Not only that, you're giving explicit content-lengths while doing so. You should be getting a hell of a lot of errors from this. Are you sure that you didn't accidentally copy/paste some code wrong here? Maybe you forgot a section at the top where you're calling ob_start()? Regardless, ditch everything before the opening <?php tag.