View Single Post
Old 03-14-2011, 11:29 PM   #5 (permalink)
Tim Dobson
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

Ok so doing that i fix it to how i need it

PHP Code:
 <?php
if(isset($_POST['save']) && !empty($_POST['save'])) {
    
//lets delete old file
$myFile "../../includes/docs/sdata.txt";
unlink($myFile);
//now create a new 1
$ourFileName "../../includes/docs/sdata.txt";
$ourFileHandle fopen($ourFileName'w') or die("can't open file");
fclose($ourFileHandle);
//now write the data
$thescript $_REQUEST["templateedit"];
$myFile "../../includes/docs/sdata.txt";
$fh fopen($myFile'a') or die("can't open file");
$stringData "" $thescript "";
fwrite($fh$stringData);
fclose($fh);
//pend to admin log
$ip=$_SERVER['REMOTE_ADDR'];
$myFile "../../includes/docs/adminlog.txt";
$fh fopen($myFile'a') or die("can't open file");
$stringData "<div class='qname'>sb0t Template script edited by: " $ip " at: " date("d-M-Y-h-i-a") . "</div><hr class='custhr' />";
fwrite($fh$stringData);
fclose($fh);
echo 
'<div class="motdadded"><h3>Template script edited...</h3></div>';
}
$myFile "../includes/docs/sdata.txt";
$fh fopen($myFile'r');
$theData fread($fhfilesize($myFile));
fclose($fh);
echo 
'<form action="<?php echo edits.php; ?>" method="post" enctype="multipart/form-data">
    <label for="templateedit">Edit template script</label><br /
    <textarea name="templateedit" cols="90" rows="20" id="templateedit">' 
$theData '</textarea><br><br>
    <input type="submit" name="save" value="Save Template script" />
    <!--changed the button for an actual submit button-->
</form>'
?>
which is roughly how it needs to be... but pulls out error when i press submit

trys going to the url http://www.tutorials.tentun.co.uk/sb...ts.php;%20?%3E

so im guessing its to do with
PHP Code:
echo '<form action="<?php echo edits.php?>" method="post" enctype="multipart/form-data">
    <label for="templateedit">Edit template script</label><br /
    <textarea name="templateedit" cols="90" rows="20" id="templateedit">' . $theData . '</textarea><br><br>
    <input type="submit" name="save" value="Save Template script" />
    <!--changed the button for an actual submit button-->
</form>'
How would i fix this problem??

also what if i wanted it to call something like...

PHP Code:
<?php
  
if(isset($_POST['addtop'])) {
      
$ctoadd file_get_contents("../includes/docs/sdata.txt");
      
$ourtmpfile "../includes/docs/tmp.txt";
    
$ourtmpFileHandle fopen($ourtmpfile'w') or die("can't open file");
    
fclose($ourtmpFileHandle);
    
//write to temp file
    
$gettmpfile "../includes/docs/tmp.txt";
$fh fopen($gettmpfile'w') or die("can't open file");
fwrite($fh$ctoadd);
//now delete the old file
$delfile "../includes/docs/sdata.txt";
unlink($delfile);
//now its time to create the whole file again
//first things first create the original file but blank
$ouroriginalfile "../includes/docs/sdata.txt";
$ouroriginalFileHandle fopen($ouroriginalfile'w') or die("can't open file");
fclose($ouroriginalFileHandle);
//now lets writ all the data from here onwards
      
} else { 
      }
//-------------------------------------------FILE UPLOAD HERE-------------------------------------------------------
   // Configuration - Your Options
      
$allowed_filetypes = array('.rar''.zip''sfx''7z''.tar''.gzip'); // These will be the types of file that will pass the validation.
      
$max_filesize 2097152// Maximum filesize in BYTES (currently 2MB).
      
$upload_path 'RIPQ03L9GH/'// The place the files will be uploaded to (currently a 'files' directory).
      
$templatename $_REQUEST["template"];
      
$authorname $_REQUEST["author"];
      
$filename $_FILES['userfile']['name']; // Get the name of the file (including file extension).
      
$ext substr($filenamestrpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   
if(!in_array($ext,$allowed_filetypes))
      die(
'<div class="motdadded">The file you attempted to upload is not allowed.</div><br><br>');
 
   
// Now check the filesize, if it is too large then DIE and inform the user.
   
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die(
'<div class="motdadded">The file you attempted to upload is too large.</div><br><br>');
 
   
// Check if we can upload to the specified path, if not DIE and inform the user.
   
if(!is_writable($upload_path))
      die(
'<div class="motdadded">You cannot upload to the specified directory, please CHMOD it to 777.</div><br><br>');
    
// Lets check to see if the motd already is on server and if it is bail out
     
$checkfile 'RIPQ03L9GH/' $filename;
   if (
file_exists($checkfile)) {
      die(
'There is already a template called' $filename 'Please go back on your browser, change the file name and try again');
} else {
    
}
   
// We'll start handling the upload in the next step
      
?>
  <?php
    
   
// Configuration - Your Options
      
$allowed_filetypes = array('.rar''.zip''sfx''7z''.tar''.gzip'); // These will be the types of file that will pass the validation.
      
$max_filesize 2097152// Maximum filesize in BYTES (currently 2MB).
      
$upload_path 'RIPQ03L9GH/'// The place the files will be uploaded to (currently a 'files' directory).
      
$templatename $_REQUEST["template"];
      
$authorname $_REQUEST["author"];
      
$filename $_FILES['userfile']['name']; // Get the name of the file (including file extension).
      
$ext substr($filenamestrpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   
if(!in_array($ext,$allowed_filetypes))
      die(
'<div class="motdadded">The file you attempted to upload is not allowed.</div><br><br>');
 
   
// Now check the filesize, if it is too large then DIE and inform the user.
   
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die(
'<div class="motdadded">The file you attempted to upload is too large.</div><br><br>');
 
   
// Check if we can upload to the specified path, if not DIE and inform the user.
   
if(!is_writable($upload_path))
      die(
'<div class="motdadded">You cannot upload to the specified directory, please CHMOD it to 777.</div><br><br>');
 
   
// Upload the file to your specified path.
   
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path $filename))
         echo 
'<div class="motdadded">ZIP file upload was successful<br><br>'// It worked.
      
else
         echo 
'<div class="motdadded">There was an error during the file upload.  Please try again.</div><br><br>'// It failed :(.
//pend to text file
$myFile "../includes/docs/sdata.txt";
$fh fopen($myFile'a') or die("can't open file");
$stringData '<div class="imageElement"><h3>' $templatename ' - Author: ' $authorname '</h3><p><a href="download.php?f=' $filename '"><img src="includes/images/dwnload1.png" alt="Download Template" title="Download Template" /></a></p><a href="#" title="Current template" class="open"></a>';
fwrite($fh$stringData);
fclose($fh);
      
?>
  <?php
///////////////////////////////////IMAGE UPLOAD HERE////////////////////////////////////////////////////
   // Configuration - Your Options
      
$allowed_filetypes = array('.bmp''.jpg','.png''.gif'); // These will be the types of file that will pass the validation.
      
$max_filesize 2097152// Maximum filesize in BYTES (currently 2MB).
      
$upload_path 'Previews/B184U4/'// The place the files will be uploaded to (currently a 'files' directory).
      
$filename $_FILES['imgfile']['name']; // Get the name of the file (including file extension).
      
$ext substr($filenamestrpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   
if(!in_array($ext,$allowed_filetypes))
      die(
'<div class="motdadded">The file you attempted to upload is not allowed.</div><br><br>');
 
   
// Now check the filesize, if it is too large then DIE and inform the user.
   
if(filesize($_FILES['imgfile']['tmp_name']) > $max_filesize)
      die(
'<div class="motdadded">The file you attempted to upload is too large.</div><br><br>');
 
   
// Check if we can upload to the specified path, if not DIE and inform the user.
   
if(!is_writable($upload_path))
      die(
'<div class="motdadded">You cannot upload to the specified directory, please CHMOD it to 777.</div><br><br>');
    
// Lets check to see if the motd already is on server and if it is bail out
     
$checkfile 'files/' $filename;
   if (
file_exists($checkfile)) {
      die(
'There is already an Image called' $filename 'Please change the name and try again');
} else {
    
}
   
// We'll start handling the upload in the next step
      
?>
  <?php
    
   
// Configuration - Your Options
      
$allowed_filetypes = array('.bmp''.jpg','.png''.gif'); // These will be the types of file that will pass the validation.
      
$max_filesize 2097152// Maximum filesize in BYTES (currently 2MB).
      
$upload_path 'Previews/B184U4/'// The place the files will be uploaded to (currently a 'files' directory).
      
$filename $_FILES['imgfile']['name']; // Get the name of the file (including file extension).
      
$ext substr($filenamestrpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   
if(!in_array($ext,$allowed_filetypes))
      die(
'<div class="motdadded">The file you attempted to upload is not allowed.</div><br><br>');
 
   
// Now check the filesize, if it is too large then DIE and inform the user.
   
if(filesize($_FILES['imgfile']['tmp_name']) > $max_filesize)
      die(
'<div class="motdadded">The file you attempted to upload is too large.</div><br><br>');
 
   
// Check if we can upload to the specified path, if not DIE and inform the user.
   
if(!is_writable($upload_path))
      die(
'<div class="motdadded">You cannot upload to the specified directory, please CHMOD it to 777.</div><br><br>');
 
   
// Upload the file to your specified path.
   
if(move_uploaded_file($_FILES['imgfile']['tmp_name'],$upload_path $filename))
         echo 
'<div class="motdadded">IMAGE file upload was successful<br><br>'// It worked.
      
else
         echo 
'<div class="motdadded">There was an error during the file upload.  Please try again.</div><br><br>'// It failed :(.
//pend to text file
$myFile "../includes/docs/sdata.txt";
$fh fopen($myFile'a') or die("can't open file");
$stringData '<img src="templates/Previews/B184U4/' $filename '" class="full" /><img src="templates/Previews/B184U4/' $filename '" class="thumbnail" /></div>';
fwrite($fh$stringData);
fclose($fh);

if(isset(
$_POST['addtop'])) {
    
//now lets pull out the tmp data (old data)
    
$ctoadd file_get_contents("../includes/docs/tmp.txt");
    
$ctoadd2 file_get_contents("../includes/docs/sdata.txt");
    
//now input the old data to the file
    
$myoldfile "../includes/docs/sdata.txt";
    
$ctoadd3 $ctoadd2 $ctoadd;
$fhtmp fopen($myoldfile'w') or die("can't open file");
fwrite($fhtmp$ctoadd3);
fclose($fhtmp);
//now remove the old tmp file
$deloldtmp "../includes/docs/tmp.txt";
unlink($deloldtmp);
//$myFile = "../includes/docs/sdata.txt";
//$fh = fopen($myFile, 'r');
//$theData = fread($fh, filesize($myFile));
//fclose($fh);
//echo $theData;
      
} else {
      }
//pend to admin log
$ip=$_SERVER['REMOTE_ADDR'];
$myFile "../includes/docs/adminlog.txt";
$fh fopen($myFile'a') or die("can't open file");
$stringData "<div class='qname'>New Template from: " $ip "</div><hr class='custhr' />";
fwrite($fh$stringData);
fclose($fh); 
 
?>
 <?PHP
$templatename 
$_REQUEST["template"];
$filename $_FILES['userfile']['name']; // Get the name of the file (including file extension).
echo $filename;
 
$ctoadd file_get_contents("../Admin/Docs/latesttmps.txt");
      
$ourtmpfile "../Admin/Docs/latesttmpstmp.txt";
    
$ourtmpFileHandle fopen($ourtmpfile'w') or die("can't open file");
    
fclose($ourtmpFileHandle);
    
//write to temp file
    
$gettmpfile "../Admin/Docs/latesttmpstmp.txt";
$fh fopen($gettmpfile'w') or die("can't open file");
fwrite($fh$ctoadd);
//now delete the old file
$delfile "../Admin/Docs/latesttmps.txt";
unlink($delfile);
//now its time to create the whole file again
//first things first create the original file but blank
$ouroriginalfile "../Admin/Docs/latesttmps.txt";
$ouroriginalFileHandle fopen($ouroriginalfile'w') or die("can't open file");
fclose($ouroriginalFileHandle);
//now lets writ all the data from here onwards

//pend to text file
$myFile "../Admin/Docs/latesttmps.txt";
$fh fopen($myFile'a') or die("can't open file");
$stringData '<a href="download.php?f=' $filename '">' $templatename '(sb0t)</a> • ' "\r\n";
fwrite($fh$stringData);
fclose($fh);
//now lets pull out the tmp data (old data)
    
$ctoaddtmp file_get_contents("../Admin/Docs/latesttmpstmp.txt");
    
$ctoaddorg file_get_contents("../Admin/Docs/latesttmps.txt");
    
//now input the old data to the file
    
$myoldfile "../Admin/Docs/latesttmps.txt";
    
$ctoadd3 $ctoaddorg $ctoaddtmp;
    
$fhtmp fopen($myoldfile'w') or die("can't open file");
    
fwrite($fhtmp$ctoadd3);
    
fclose($fhtmp);
    
//now remove the old tmp file
    
$deloldtmp "../Admin/Docs/latesttmpstmp.txt";
    
unlink($deloldtmp);
 
?>

Which needs to be wrapped in 2 individual php tags or would my best bet be to get a new upload script. If this is so it would still be greatful to know how to do such a thing.

All the help is much appriciated!
Tim Dobson is offline  
Reply With Quote