Idontwantspam Posted August 21, 2007 Share Posted August 21, 2007 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??? Link to comment Share on other sites More sharing options...
ripken204 Posted August 21, 2007 Share Posted August 21, 2007 (edited) 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, 2007 by ripken204 Link to comment Share on other sites More sharing options...
Idontwantspam Posted August 22, 2007 Author Share Posted August 22, 2007 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? Link to comment Share on other sites More sharing options...
Idontwantspam Posted August 22, 2007 Author Share Posted August 22, 2007 Never mind. I figured it out now. I need to put stripslashes() around the text before processing it. Link to comment Share on other sites More sharing options...
ripken204 Posted August 22, 2007 Share Posted August 22, 2007 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 Link to comment Share on other sites More sharing options...
Idontwantspam Posted August 22, 2007 Author Share Posted August 22, 2007 (edited) 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, 2007 by Idontwantspam Link to comment Share on other sites More sharing options...
ripken204 Posted August 23, 2007 Share Posted August 23, 2007 i dont think that there is a way, i think it's more dependant on the browser.. Link to comment Share on other sites More sharing options...
Idontwantspam Posted August 23, 2007 Author Share Posted August 23, 2007 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. Link to comment Share on other sites More sharing options...
ripken204 Posted August 23, 2007 Share Posted August 23, 2007 maybe something with javascript.. Link to comment Share on other sites More sharing options...
Idontwantspam Posted August 23, 2007 Author Share Posted August 23, 2007 According to everything I've found, it's not possible. Link to comment Share on other sites More sharing options...
Chozo4 Posted August 24, 2007 Share Posted August 24, 2007 (edited) 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, 2007 by Chozo4 Link to comment Share on other sites More sharing options...
Zxian Posted August 24, 2007 Share Posted August 24, 2007 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. Link to comment Share on other sites More sharing options...
Idontwantspam Posted August 24, 2007 Author Share Posted August 24, 2007 OK, thanks. One question about that, how would I actually make a link to the download? Where does the <a href=... go? Link to comment Share on other sites More sharing options...
ripken204 Posted August 24, 2007 Share Posted August 24, 2007 (edited) 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, 2007 by ripken204 Link to comment Share on other sites More sharing options...
Idontwantspam Posted August 24, 2007 Author Share Posted August 24, 2007 OK, thanks, I'll try that. Thanks for your help everyone! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now