Jump to content

ozPATT

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ozPATT's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. is that a predefined function? never heard of it. glad to help Gruzin
  2. if only i could! haha, it is a piece of code that I acquired some time ago, and uses regular expressions. Basically, it replaces any line returns from the textarea, with the paragraph and break tags that html uses. eg \r\n is one line break or return. so that should be <br />. two of them, equal a paragraph, which is <p></p>. Pretty clever really. Did it do what you wanted?
  3. this any good? [code]$text = stripslashes (preg_replace(array("/\r?\n\r?\n/","/\r\n/"),array("</p>\n\n<p>","<br />\n"),$_POST['text']));[/code]
  4. you should be able to put tables, paragraphs, etc into a form? So you just have the one form I would have thought. Have you tried starting the form at the top of the page, and ending it at the bottom, after the submit? if so, what happened?
  5. not too hot on arrays, but I usually pass the page in the url, so the index page looks like: [code]if(isset($_GET['page'])) { $page = $_GET['page']; } else { $page = "home"; } require_once($page . ".php");[/code] this way, I store all the content in a separate folder called "content" funnily enough, and index page is just used to display it. So you might have the following page and link: Home = index.php News = index.php?page=news About = index.php?page=about Contact = index.php?page=contact if that makes sense. :)
  6. this is a cool class to do what you want... usage is at the bottom, and you can either upload with no validation, or with. pretty easy to get your head around, just copy all this into a file, call it something like class.fileupload.php, and include that in your page. then use the usage instructions at the bottom, wherever you want to use it. [code]<?php   class Upload_Files { //vars var $temp_file_name; var $file_name; var $upload_dir; var $upload_log_dir; var $max_file_size; var $banned_array; var $ext_array;     //Validation of file extensions function validate_extension() { //set vars $file_name = trim($this->file_name); $extension = strtolower(strchr($file_name, ".")); $ext_array = $this->ext_array; $ext_count = count($ext_array); //start validation process if(!$file_name) { return false; } else { if(!$ext_array) { return true; } else { //put extensions into an array foreach($ext_array as $value) { $first_char = substr($value, 0, 1); if($first_char <> ".") { $extensions[] = "." . strtolower($value); } else { $extensions[] = strtolower($value); } }   //find out if the extension is valid foreach($extensions as $value) { if($value == $extension) { $valid_extension = true; } }   //is the $valid_extension variable present? if($valid_extension) { return true; } else { return false; } } } } //validation of file size function validate_size() { $temp_file_name = trim($this->temp_file_name); $max_file_size = trim($this->max_file_size); if($temp_file_name) { $size = filesize($temp_file_name); if($size > $max_file_size) { return false; } else { return true; } } else { return false; } } //does file already exist? function existing_file() { $file_name = trim($this->file_name); $upload_dir = $this->get_upload_directory(); if($upload_dir == "ERROR") { return true; } else { $file = $upload_dir . $file_name; if(file_exists($file)) { return true; } else { return false; } } } //extract the file size function get_file_size() { $temp_file_name = trim($this->temp_file_name); $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; if($temp_file_name) { $size = filesize($temp_file_name); if($size < $kb) { $file_size = "$size Bytes"; } elseif($size < $mb) { $final = round($size/$kb, 2); $file_size = "$final KB"; } elseif($size < $gb) { $final = round($size/$mb, 2); $file_size = "$final MB"; } elseif($size < $tb) { $final = round($size/$gb, 2); $file_size = "$final GB"; } else { $final = round($size/$tb, 2); $file_size = "$final TB"; } } else { $file_size = "ERROR NO FILE PASSED TO get_file_size()"; } return $file_size; } //extract the max file size function get_max_size() { $max_file_size = trim($this->max_file_size); $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; if($max_file_size) { if($max_file_size < $kb) { $max_file_size = "$max_file_size Bytes"; } elseif($max_file_size < $mb) { $final = round($max_file_size/$kb, 2); $max_file_size = "$final KB"; } elseif($max_file_size < $gb) { $final = round($max_file_size/$mb, 2); $max_file_size = "$final MB"; } elseif($max_file_size < $tb) { $final = round($max_file_size/$gb, 2); $max_file_size = "$final GB"; } else { $final = round($max_file_size/$tb, 2); $max_file_size = "$final TB"; } } else { $max_file_size = "ERROR: NO SIZE PARAMETER PASSED TO get_max_size()"; } return $max_file_size; } //validation of the user function validate_user() { $banned_array = $this->banned_array; $ip          = trim($_SERVER['REMOTE_ADDR']); $cpu          = gethostbyaddr($ip); $count        = count($banned_array); if($count < 1) { return true; } else { foreach($banned_array as $key => $value) { if($value == $ip . "-" . $cpu) { return false; } else { return true; } } } } //verify the upload directory function get_upload_directory() { $upload_dir = trim($this->upload_dir); if($upload_dir) { $ud_len = strlen($upload_dir); $last_slash = substr($upload_dir, $ud_len-1, 1); if($last_sleash <> "/") { $upload_dir = $upload_dir . "/"; } else { $upload_dir = $upload_dir; } $handle = @opendir($upload_dir); if($handle) { $upload_dir = $upload_dir; closedir($handle); } else { $upload_dir = "ERROR"; } } else { $upload_dir = "ERROR"; } return $upload_dir; } //verify the upload log directory function get_upload_log_directory() { $upload_log_dir = trim($this->upload_log_dir); if($upload_log_dir) { $ud_len = strlen($upload_log_dir); $last_slash = substr($upload_log_dir, $ud_len-1, 1); if($last_slash <> "/") { $upload_log_dir = $upload_log_dir . "/"; } else { $upload_log_dir = $upload_log_dir; } $handle = @opendir($upload_log_dir); if($handle) { $upload_log_dir = $upload_log_dir; closedir($handle); } else { $upload_log_dir = "ERROR"; } } else { $upload_log_dir = "ERROR"; } return $upload_log_dir; } //upload the file with no validation function upload_file_no_validation() { $temp_file_name = trim($this->temp_file_name); $file_name      = trim(strtolower($this->file_name)); $upload_dir    = $this->get_upload_directory(); $upload_log_dir = $this->get_upload_log_directory(); $file_size      = $this->get_file_size(); $ip            = trim($_SERVER['REMOTE_ADDR']); $cpu            = gethostbyaddr($ip); $m              = date("m"); $d              = date("d"); $y              = date("Y"); $date          = date("m/d/Y"); $time          = date("h:i:s A"); if(($upload_dir == "ERROR") || ($upload_log_dir == "ERROR")) { return false; } else { if(is_uploaded_file($temp_file_name)) { if(move_uploaded_file($temp_file_name, $upload_dir . $_SESSION['uid'] . '_' . $file_name)) { $log = $upload_log_dir . $y . "_" . $m . "_" . $d . ".txt"; $fp = fopen($log, "a+"); fwrite($fp, "$ip-$cpu | $file_name | $file_size | $date | $time"); fclose($fp); return true; } else { return false; } } else { return false; } } } //upload file with validation function upload_file_with_validation() { $temp_file_name = trim($this->temp_file_name); $file_name      = trim(strtolower($this->file_name)); $upload_dir    = $this->get_upload_directory(); $upload_log_dir = $this->get_upload_log_directory(); $file_size      = $this->get_file_size(); $ip            = trim($_SERVER['REMOTE_ADDR']); $cpu            = gethostbyaddr($ip); $m              = date("m"); $d              = date("d"); $y              = date("Y"); $date          = date("m/d/Y"); $time          = date("h:i:s A"); $existing_file  = $this->existing_file(); $valid_user    = $this->validate_user(); $valid_size    = $this->validate_size(); $valid_ext    = $this->validate_extension(); if(($upload_dir == "ERROR") || ($upload_log_dir == "ERROR")) { return false; } elseif((((!$valid_user) || (!$valid_ext) || (!$valid_size) || ($existing_file)))) { return false; } else { if(is_uploaded_file($temp_file_name)) { if(move_uploaded_file($temp_file_name, $upload_dir . $file_name)) { $log = $upload_log_dir . $y . "_" . $m . "_" . $d . ".txt"; $fp = fopen($log, "a+"); fwrite($fp, "$ip-$cpu | $file_name | $file_size | $date | $time"); fclose($fp); return true; } else { return false; } } else { return false; } } } } //usage /* $upload_class = new Upload_Files; $upload_class->temp_file_name = trim($_FILES['upload']['tmp_name']); $upload_class->file_name = trim(strtolower($_FILES['upload']['name'])); $upload_class->upload_dir = "uploads/"; $upload_class->upload_log_dir = "uploads/upload_logs/"; $upload_class->max_file_size = 524288; $upload_class->banned_array = array(""); $upload_class->ext_array = array(".jpg", ".gif", ".jpeg", ".png"); $valid_ext = $upload_class->validate_extension(); $valid_size = $upload_class->validate_size(); $validate_user = $upload_class->validate_user(); $max_size = $upload_class->get_max_size(); $file_size = $upload_class->get_file_size(); $upload_directory= $upload_class->get_upload_directory(); $upload_log_directory = $upload_class->get_upload_log_directory(); $upload_file = $upload_class->upload_file_with_validation(); */ ?> [/code] any questions, just ask...
  7. haha, welcome to the world of cross-broswer compliance! ;) as for your file issue, i agree with the above, but as i don't see any tagme link on the main site, I'm not sure either what the problem is exactly. In your ftp program, you should be able to set it up so that when you log in, it goes straight to the www folder, saving you the hassle of searching through everything. then in that, if you put all your main files in there, then have an 'images' folder, and an 'includes' folder, it should keep everything pretty straight forward. hope that helps! Patrick
  8. $fileName = $_FILES['uploaded']['name']; if ($fileName =="text/php") aren't you setting the filename to be the actual name of the file? not the file type? not sure if that has anything to do with anything, but just an observation...
  9. any more information you can provide? i dont really understand what you are wanting to achieve...
  10. ooh, that looks like it could be just the ticket... i will give that a try and let you know how i get on. thanks for that! woohoo!! worked! :o) thanks! Now I just need to work out another scripting problem, but perhaps you could help me with that too if you have time? My client needs to enter articles onto his site, done the same way. Currently, he includes some javascript that will open up a popup window, and show the user an image, stored in the popup directory. I need to find a way to incorporate this into the site, and I think a similar way would be good. What I am thinking, is if he was to put: [popup="image.jpg"] wherever he wanted these popups to go, then i just extract where it says the above, and take out what is in the quote marks. then replace, using the extracted as the href src or something like that. does that make sense? thanks for your help with the above again. :)
  11. haha, thanks again for the reply, but I think  i am not being too clear... i have the function to mask the email, my problem is actually getting the email address from the text, as there may be several addresses in one section. So each address will need to be replaced, with the function call. if that makes sense., thanks for the prrompt replies though...
  12. not sure i understand entirely what you want to do... do you mean you ONLY want the link to show if "A" is present? The following code will only display the link if EstatTecnic is equal to "A". [code]<?php //build and run query $sql = "SELECT * FROM ..."; $result = mysql_query($sql); //is something wrong? if(!$result) { echo mysql_error(); } //count results $count = mysql_num_rows($result); //if no results, tell user, if results, display. if($count == 0) { $display = ('<p>There are no results.</p>'); //modify error message to be what you want. } else { //build array to pull data from db while($row = mysql_fetch_array) { //set vars $EstatTecnic = $row['NumTecnic']; } //build table, only display link if EstatTecnic is equal to "A" $display = ('<table><tr><td>'); if($EstatTecnic == "A") { $display .= ('<a href="tecnic.php?tecnic=' . $EstatTecnic . '" title="see" target="_self">see</a>'); } $display .= ('</td></tr></table>'); } //echo everything echo($display); ?>[/code]
  13. sorry, must not have explained properly... I need to mask email addresses. So I have a function, that takes 2 arguments, the user and the domain. For every email address in a given text, i need to replace it with say, MaskEmail($email) - $email being the address...
  14. Hi All, I have a CMS, where people enter information into a textarea, that gets inserted into a db. What I would like to do, is replace all email addresses, with a function that will mask the address, but to do that, i need to find a way to find the address to replace. I can find the @ easy enough, but I don't know how to get the whole address. Any help would be good. Thanks Patrick
  15. Hi all, Does anyone know where I could find a tutorial to help me create a database driven multi-lingual website? I would like to be able to edit the content easily as well as adding new languages on the fly... if possible. If anyone has any ideas on how to set up the db tables, and the code, or if you know of a tutorial, I'd love to find out. to fill you in, I built [a href=\"http://www.tabara-targujiu.com\" target=\"_blank\"]this website[/a] last year, but it doesn't include functionality to edit the content, or to include new languages. I would like to revisit this website, and build it more robust and easier to maintain.
×
×
  • 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.