August 21, 200719 yr OK, here's my problem. I have a php form that submits an email with the text the user specifies, and it works fine except that all of the \ symbols and ' symbols have a \ before them. Is there any way to stop this? It happens with any form element submitted to a form. For example:This is part of "form.html"<form action="example.php" method="post"><input type="text" value="" id="example1" name="example1" /><input type="submit" value="Submit" id="example2" name="example2" /></form>The text field "example1" gets filled in with Example: \ 'And then there's example.php:<?php echo $_POST["example1"] ?>Which will display:Example: \\ \'How can I stop this???
August 21, 200719 yr well there is more code that you are leaving out, i need to see that instead of the examples.my guess is that you are doing <input value=$_POST["example1"] /> and this could cause problems with the slash, make sure to do <input value="$_POST['example1']" /> <?=$_POST["example1"] ?><form action="<?=$_SERVER[php_self]?>" method="post"><input type="text" value="" id="example1" name="example1" /><input type="submit" value="Submit" id="example2" name="example2" /></form>this works perfectly for me.. Edited August 21, 200719 yr by ripken204
August 22, 200719 yr Author I'm not sure I understand your reply. This happens with any form element getting processed in any way by php. Here is a full-document example. page1.html:<html><head> <title>Example</title></head><body><p>This is an example.</p><form action="example.php" method="post">Your name is: <input type="text" value="" id="yourname" name="yourname" /></form></body></html>example.php<html><head> <title>My name is <?php echo $_POST["yourname"] ?></title></head><body>Hello, <?php echo $_POST["yourname"] ?>. Welcome to this example page!</body></html>Now, say for example, someone's name is John O'rielly. Well, example.php would display the html code as follows:<html><head> <title>My name is John O\'rielly</title></head><body>Hello, John O\'rielly. Welcome to this example page!</body></html>What I want to do is prevent it from showing that backslash. Does that explain it better? I hope?
August 22, 200719 yr Author Never mind. I figured it out now. I need to put stripslashes() around the text before processing it.
August 22, 200719 yr oh now why didnt u just say O'Reilly before! lol. i had the same problem when i was doing a database with a name entry system a few months ago
August 22, 200719 yr Author oh now why didnt u just say O'Reilly before! lol. i had the same problem when i was doing a database with a name entry system a few months ago Sorry. I guess I didn't give a good example. Oh well, thanks for trying anyway! ..And no, my name is not O'Rielly. --------------Now I have a new question. How can I make a link to a file so that it will download the file rather than open it in the browser? For example, if there's a PDF document on a site and I link to it using the standard <a href="... method, it just opens in the window specified by target=. Is there a value for target= that will specify download, or some other option like that? Thanks in advance. Edited August 22, 200719 yr by Idontwantspam
August 23, 200719 yr Author Well, I don't think so, actually. For example, if someone uploads an attachment to MSFN that is in .html format, clicking on the link to it opens the download dialog; it doesn't open the html file. I'll go look at the source for some pages that offer download rather than direct links and see if I can figure it out.
August 24, 200719 yr That can be done through php with the use of Header() andn changing the content disposition. The info for that and more can be found at http://www.php.net/manual/en/function.header.phpHere is one of the examples that may be relevant to your needs.Example 1578. Download dialogIf you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the » Content-Disposition header to supply a recommended filename and force the browser to display the save dialog. <?php// We'll be outputting a PDFheader('Content-type: application/pdf');// It will be called downloaded.pdfheader('Content-Disposition: attachment; filename="downloaded.pdf"');// The PDF source is in original.pdfreadfile('original.pdf');?>Be sure to read some of the user contributed notes for more hints and ideas on how to use this method to it's fullest with other file formats as well. Edited August 24, 200719 yr by Chozo4
August 24, 200719 yr Just another useful note - what Chozo4 posted can also be used to prevent hotlinking of files. Checking wether or not a session variable has been set (you set it from the main page) within that download.php file (or whatever you call it) will prevent hotlinking.
August 24, 200719 yr Author OK, thanks. One question about that, how would I actually make a link to the download? Where does the <a href=... go?
August 24, 200719 yr well it would be best to make a function out of it so that you could reuse ityou would call it by doing: <a target="_blank" href="<?=download('file.pdf');?>">text</a>then the function would be:<? function download($file){ header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename=$file'); readfile($file); }?>edit:now you will have to make the link open a new page as well because when you do header() it has to be the first thing on the page, nothing can display on the page before you call it. so i added in the target=_blankthis should work, i just wrote it out here and didnt test it.. Edited August 24, 200719 yr by ripken204
Create an account or sign in to comment