cheesycarrion Posted March 1, 2007 Share Posted March 1, 2007 I havn't tested this yet. I just want to know if I'm doing it right. I'm only showing one part of the script, but it's all that you will need. I have a post form that has a bunch of fields and when submitted, it should create a php file with some variables defined in it. If you're wondering what it's for, its so that moderators of my site can add items to the downloads section. notice that the code messed up the color coding thing on this forum. I don't want it to do a similiar screwup and give me a bunch of parse errors. here's what I have so far: <?php // start of relevant code // authentication script that I've already made. Sets $cc_auth_mod and $cc_auth_admin to 1 or 0 // it also includes the userdata from the forum, to which my site is based around include "html/auth.php"; if ($cc_auth_mod=="1"||$cc_auth_admin=="1") { $dl_desk_dafile = "storage_dump/downloads/descriptions/" . $_POST["addr_title"] . ".php"; // the php page created should show this php code with the username of the person who uploaded it in a note $dl_description_template = "<?php // download added by " . $userdata["username"] . " $dldescription = \"" . $_POST["description"] . "\"; $dllink = \"" . $_POST["link"] . "\"; $dlcreator = \"" . $_POST["creator"] . "\"; $dlonclick = \"" . $_POST["onclick"] . "\"; $dldl = \"" . $_POST["download"] . "\"; $dlimage = \"" . $_POST["image"] . "\"; ?>"; $dl_desk_dafile = "storage_dump/downloads/descriptions/" . $_POST["addr_title"] . ".php"; if (!file_exists($dl_desk_dafile)) { $description_fopen = fopen($dl_desk_dafile, "x") or exit("A Very Unusual Error Has Occurred. Congratulation!"); echo fwrite($dl_desk_dafile, $dl_description_template); fclose ($dl_desk_dafile); } else { echo "There is already a description for this download"; } } else { echo "you are not a moderator. go away."; } ?> Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 some modification hre... $description_fopen = fopen($dl_desk_dafile, "x") or exit("A Very Unusual Error Has Occurred. Congratulation!"); echo fwrite($dl_desk_dafile, $dl_description_template); fclose ($dl_desk_dafile); use this:: $description_fopen = fopen($dl_desk_dafile, "w") or exit("A Very Unusual Error Has Occurred. Congratulation!"); echo fwrite($description_fopen, $dl_description_template); fclose ($dl_desk_dafile); Quote Link to comment Share on other sites More sharing options...
cheesycarrion Posted March 2, 2007 Author Share Posted March 2, 2007 So I changed it around a little bit because I didn't want to deal with all of the fancy input boxes. I just wrote a textarea with default values in it and said to write <?php at the top and ?> at the bottom. You can see the code below. Here's the current problem: When first trying to submit: Warning: fwrite(): supplied argument is not a valid stream resource in /home/.juice/km162/sam.kingmuffin.net/modcp_downloads_fup.php on line 170 Warning: fclose(): supplied argument is not a valid stream resource in /home/.juice/km162/sam.kingmuffin.net/modcp_downloads_fup.php on line 171 When trying to post again: There is already a description for this download. If you need it to be changed, contact me. When I checked the folder with ftp, I saw that the file was created with the correct title, but had no contents. Here's the snippet code (note that this isn't the whole file, since I have other pages on it with get variables. They don't interfere with this: <?php // lots of code before here. tell me if you need line numbers. elseif ($_GET["page"]=="desc"&&$_POST==null) { ?> <form action="modcp_downloads_fup.php" method="post"> <p>req = required opt = optional <p>if optional, delete the entire line.</p> <h3>At the beginning, write <?php (and hit return) and at the end write ?> (and hit return).</h3> <p>Remember the title that you enter below</p> <input type="text" name="titlewospaces" value="title_no_spaces_lowercase" /> <input type="hidden" name="page" value="step2submit" /> <textarea name="download_description_data" style="width: 500px; height: 600px; "> // add php opening statement above this line // // Please follow instructions written in the following notes. // // this download added by <?php echo $userdata["username"]; ?>. // // 1: link (where you got the download from origionally with http) req $dllink = "http://sitename.com/whatever"; // 2: creator (who made the file / program) req $dlcreator = "Full Name Goes Here"; // 3: Firefox onClick event opt // // delete the whole line if this isn't a Firefox extension // To find the onclick, view source on the download page // that you got it from. ctrl+f for ".xpi" and then find // the onClick="blahblahblah" that is very near it. Then // copy the value (blahblahblah) and paste it in this next // thing's value. $dlonclick = ""; // 4: download link req // (where the file uploaded on the previous step - relative location) $dldl = "storage_dump/downloads/files/theshit.zip"; // 5: image (relative location like above.) opt. $dlimage = ""; // place php closing statement below this line. </textarea> Once you click continue, you cannot modify or delete the description file. <input type="submit" value="continue" /> <input type="reset" value="start over" /> </form> <?php } elseif ($_GET["page"]==null&&$_POST["page"]=="step2submit") { // makin the file $dl_desk_dafile = "storage_dump/downloads/descriptions/" . $_POST["titlewospaces"] . ".php"; if (!file_exists($dl_desk_dafile)) { // if file does not exist $description_fopen = fopen($dl_desk_dafile, "w") or exit("A Very Unusual Error Has Occurred. Congratulation!"); echo fwrite($dl_desk_dafile, $_POST["download_description_data"]); fclose ($dl_desk_dafile); // end if file does not exist } else { echo "There is already a description for this download. If you need it to be changed, contact me."; } // end script for makin the file } } if you want me to make a test moderator account, private message me. Quote Link to comment Share on other sites More sharing options...
cheesycarrion Posted March 2, 2007 Author Share Posted March 2, 2007 I didn't see what you had changed on the second line. works now. only problem is, when there is sucess making the file, it just said "1045". ??? Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 You havent changed the code fully with what I gave you replace this code:: $description_fopen = fopen($dl_desk_dafile, "w") or exit("A Very Unusual Error Has Occurred. Congratulation!"); echo fwrite($dl_desk_dafile, $_POST["download_description_data"]); fclose ($dl_desk_dafile); with this one... $description_fopen = fopen($dl_desk_dafile, "w") or exit("A Very Unusual Error Has Occurred. Congratulation!"); echo fwrite($description_fopen, $_POST["download_description_data"]); fclose ($description_fopen); Quote Link to comment Share on other sites More sharing options...
cheesycarrion Posted March 2, 2007 Author Share Posted March 2, 2007 You havent changed the code fully with what I gave you replace this code:: $description_fopen = fopen($dl_desk_dafile, "w") or exit("A Very Unusual Error Has Occurred. Congratulation!"); echo fwrite($dl_desk_dafile, $_POST["download_description_data"]); fclose ($dl_desk_dafile); with this one... $description_fopen = fopen($dl_desk_dafile, "w") or exit("A Very Unusual Error Has Occurred. Congratulation!"); echo fwrite($description_fopen, $_POST["download_description_data"]); fclose ($description_fopen); I saw the part that I had missed after I posted the first part, but then changed it. Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 did u try to find whats coming in "$_POST["download_description_data"]);" try echo $_POST["download_description_data"]);and c if you have any value in it... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.