PHP - How To Block The Word Php From File Name?
Can this be done easily enough with php? I've attached my current code below, but don't see how i could add this in.
Code: [Select] $name = $_FILES['file']['name']; $temp = $_FILES['file']['tmp_name']; $size = $_FILES['file']['size']; $random = md5(uniqid(rand(), true)); $random = substr($random, 0, 20); if (!$name || !$temp || !$size) { echo "Go back and select a file."; exit(); } foreach ($_FILES as $file) { if ($file['tmp_name'] != null) { $thisext1=explode(".", strtolower($file['name'])); $thisext=$thisext1[count($thisext1)-1]; if (!in_array($thisext, $extensions)) { echo "That file type is not allowed."; exit(); } } } Similar TutorialsHi, I want that user can only read my article but can't download it. neither with save page as or with view source, even not with selecting text. and copy and paste. is there any solution in php to do that. Please help Thanks for example, i want to search for an the string "example@example.com" and erase it. thanks in advance ! Hi all, I am in need of php code for word file conversion. That is to convert word .docx file to .doc file Someone please provide me with a solution. Thanks. please it is very important!! I have a script (main file is index.php) that is called into an iframe src via an url reference... http://www.xxxx.com/folder/userfolder/folderwithemailname/index.php works perfectly!!.. How can i prevent someone getting direct url access to the file? if someone were to take the url: http://www.xxxx.com/folder/userfolder/folderwithemailname/index.php and place it into the address bar, they have access to the file... points to note: -i have no database for this script, -the iframe is called directly into a html file, - i dont know the userfolder or the emailfolder names, - and the index.php is linked to several other .php and .js and .html files in different folders.... // i can add something like this to these file:(i found this on the net). Add this to the page that you want to only be included <?php if(!defined('MyConst'){die('Direct access not premitted');} ?> then on the pages that include it add <?php define('MyConst', TRUE); ?> this will prevent the files being accessed, but then i cant access the file via the iframe url.. please any ideas??? best regards Tony Hi By the the way the server this site is hosted on is flipping fast! I'm still a php beginner. I have a php file, the entire code is he <?php get_header(); ?> <?php if(!is_paged()) { ?> <div id="top" class="clearfloat"> <div id="headline"> <?php if ( function_exists('show_nivo_slider') ) { show_nivo_slider(); } ?> </div> <div id="featured"> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(8) ) : ?> <?php endif; ?> </div> </div> <div id="middle" class="clearfloat"> <?php $display_categories = array(7, 13, 17, 18, 1528); $i = 1; foreach ($display_categories as $category) { ?> <div id="cat-<?php echo $i; ?>" class="category"> <?php query_posts("showposts=1&cat=$category")?> <span class="cat_title"><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a></span> <a href="<?php echo get_category_link($category);?>"></a> </div> <?php $i++; ?> <?php } ?> </div> <?php } ?> <div id="bottom" class="clearfloat"> <div id="front-list"> <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("cat=-27,-28&paged=$page&posts_per_page=10"); ?> <?php while (have_posts()) : the_post(); ?> <div class="clearfloat"> <h3 class=cat_title><?php the_category(', '); ?> »</h3> <div class="title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div> <div class="meta">[<?php the_time('j M Y') ?> | <?php comments_popup_link('No Comment', 'One Comment', '% Comments');?> | <?php if(function_exists('the_views')) { the_views(); } ?>]</div> <div class="spoiler"> <?php $values = get_post_custom_values("Image"); if (isset($values[0])) { ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php $values = get_post_custom_values("Image"); echo $values[0]; ?>&w=150&h=150&zc=1&q=100" alt="<?php the_title(); ?>" class="left" width="150px" height="150px" /></a> <?php } ?> <?php the_excerpt(); ?> </div> </div> <?php endwhile; ?> <div class="navigation"> <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?> <div class="right"><?php next_posts_link('Next Page »') ?></div> <div class="left"><?php previous_posts_link('« Previous Page') ?></div> <?php } ?> </div> </div> <?php get_sidebar(); ?> </div> <?php get_footer(); ?> I want to remove the following block on line 19 to 33 because I don't need it: <?php $display_categories = array(7, 13, 17, 18, 1528); $i = 1; foreach ($display_categories as $category) { ?> <div id="cat-<?php echo $i; ?>" class="category"> <?php query_posts("showposts=1&cat=$category")?> <span class="cat_title"><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a></span> <a href="<?php echo get_category_link($category);?>"></a> </div> <?php $i++; ?> <?php } ?> </div> <?php } ?> But when I remove that I get the error, unexpected end of file error and references to <?php get_footer(); ?> I need to understand why this is happening, not just how to fix it (although I need that too). My suspicion is one of the endif's. I'm pretty sure this is really simple to do using the count function, but I am having a hard time finding examples on how to count the number of times a "SPECIFIC" word occurs in a file. For example, I just want to display how many times "this-word" occurs in "http://www.mysite.com/logfile.log". Any help would be appreciated. Other than downloading the file, editing it on the local PC, saving it, and uploading it back to the server using some applicable script, any ideas?
Hey, I'm trying to open a .php file and read a comment block that is in the beginning of the file. I'm having some trouble in that nothing is being echoed out. Here is the reading file: <?php $fb = fopen("tepl.php", "r"); $data = fread($fb, 8192); fclose($fb); var_dump($data); ?> here is the file (tepl.php) being read: <?php /* Name: Test Plugin 1 URI: http://www.theorangeday.com/plugintest/ Description: This is just a test plugin because I need to test how this thing is going to work overall. Author: Thomas Francis Author URI: http://www.theorangeday.com/ Version: 0.1 */ function test_plugin(){ echo "we loaded the test plug"; } ?> the var_dump returns Code: [Select] string(321) " " What's wrong here? Hi all, I have a function that is only used in the file it is declared in : /index.php Code: [Select] /** * This function is used to display form messages. * * @param string $msg This explains login and session status . * * @access private * * @return string */ function pred($msg) { return "<p class='content' style='color:red;'> $msg</p>"; } I'm using netbeans 7.0 (which by the way rocks !!!!! ), and I don't want to be able to see the documentation in other files when I start typing something similar. I read at pear.net coding standards that the '@param private' can be used on class methods. Is there a way to make the documentation private to the file that the function is declared in? I'm simply trying not to flood other files in the project with needless function suggestions. Thanks in advance. I have been reading most spambots use UTC-12 timezone and PHbb has a hack to block UTC-12, but I dont have the file I am looking to get the UTC ( or GMT ) time from the referring page any ideas? How is it that a site can forward to my site without a trace? www.2mysite.com is forwarding traffic to www.mysite.com but $page_name = $_SERVER['HTTP_REFERER']; echo $page_name; does not show www.2mysite.com as the referring site...how does one hide this? Help? I draw contents from a database. Some of the texts contain a footnote, which is formatted using a div class. Following the HTML of this:
<div class=""footnotes""> <br> <hr align=""left"" noshade=""noshade"" size=""1"" width=""150"" /> <blockquote> <a href=""#f1"" name=""fn1""> <span class=""superscript""> * </span> </a>Some footnotetext</blockquote></div>Since my bibliography uses data from the database as well, the footnote now appears before the references, but I would like it at the very bottom of the page. I was thinking of using preg_replace in order to separate the textfield into two variables, one for the text itself, the other one for the footnote (it is always just one) and integrate after the bibliography is compiled. Unfortunately, it seems that the preg_replace does not work. It always displays the whole content of the textfield. Here's the PHP: $text = preg_replace('/(.*)(\div class=\"footnotes\"\>.*?\<\/div\>)/s', '$1', $result['text']);$footnote = preg_replace('/(.*)(\div class=\"footnotes\"\>.+?\<\/div\>)/s', '$2', $result['text']); echo '<div align="justify"><span style="font-family:Georgia;font-size:16px;">' . $text; ***BIBLIOGRAPHY*** ... echo $footnote;Maybe someone has an idea how to deal with that. I tried it on phpliveregex. There search string works fine. Many thanks for any help. how to block someone from visiting my page using ip adress ? this is the case if someone come to my site then we record the ip address and put it into database. when the visitor come again with the same IP they cannot see my page (block them) and redirect it to somewhere page. It's one of those days after a long weekend and a rainy morning. Simply trying to get the correct message depending on the variable's value if($a = 'one'){ echo "POOR";} if($a = 'two'){ echo "GOOD";} if($a = 'three'){ echo "VERY GOOD";} if($a = 'four'){ echo "EXCELLENT";} Not sure if I need to use ==, extra quotes, or ELSEIF for the best result.
Say I have a server written in PHP (don't ask ). Let's say I have 10 users connected to my script and one of those users, for the sake of the example, needs 10MB of data sent to them. If I send that data via socket_write(), does my program execution stop (therefor locking up every other user) until the data has gone through, or is the actual task of sending data over the tubes passed on to some lower level OS function so my program can get on with its flow? In PHP? Let's say I'm going off of: width x height So this is 2x1 2x1 2 blocks across, 1 block height. How do I check this against other blocks in php to see if the 2x1 will overlap another set of dimensions dynamically? Am I over thinking this? Edited by Monkuar, 24 January 2015 - 12:08 PM. Hello, Basically, What I'm looking for would be for a method of blocking certain email addresses from being submitted in a form, I need it to block certain emails that are on the list. I think the best way to describe it would be a form submission blacklist that is checked before it gets submitted. Many thanks I have the code below working perfectly, but I was wondering if there is a more eloquent way to write this, specifically handling the exceptions... This creates an object of a Router Class that parses my clean URLs into a Controller name, method name and the rest are arguments. So for example: www.domain.com/users/view/profile/bobsmith would route to the Users Controller, and find the viewUsers method and pass the arguments "profile" and "bobsmith" to it, and the method would take it from there... works great. That explains what this code does. My only question is if there is a cleaner way to handle the exceptions, so I don't have "throw new exception" written four times. Thoughts? Or is it good to go? $rawURL = getPageURL(); $router = new Router($rawURL,$rootDIR); $controller = $router->getController(); $method = $router->getMethod(); $arguments = $router->getArguments(); try { // check controller exists and set controller path // if ((isset($controller) && ($controller != ''))) { $controllerPath = APPLICATION_PATH . "controllers/" . $controller . ".class.php"; // check controller path exists // if (file_exists($controllerPath)) { // set method name and check method exists // if ((isset($method) && ($method != ''))) { $methodName = $method . ucfirst($controller); if (method_exists($controller, $methodName)) { // test it out // $test = new $controller(); $response = $test->$methodName($arguments[0]); echo $response; } else { // method_exists failed // throw new Exception("That method does not exist foo!"); } } else { // method was not found in URL // throw new Exception("No method name was given foo!"); } } else { // file_exists failed // throw new Exception("That controller does not exist foo!"); } } else { // controller was not found in URL // throw new Exception("No controller name was given foo!"); } } catch (Exception $e) { // spit it out foo // echo $e->getMessage(); } So I'm debating whats the best method. I'm aware that catch/blocks should be used in exceptional cases but what if it saves me from having 4 nested if/else conditions? The following is code for an xbox registration site Code: [Select] try { // check code is valid $c1 = $this->input->post('code1',true); $c2 = $this->input->post('code2',true); $c3 = $this->input->post('code3',true); $gt = $this->input->post('gamertag',true); $pass = $this->input->post('password',true); if( $c1 == '' || $c2 == '' || $c3 == '') { throw new FormError("Authorization code invalid."); } // check db for code validation $q = $this->db->query("select * from `codes` where `activated` = 0 and `code` = ".$c1.$c2.$c3." limit 0,1"); if($q->num_rows() != 1) { throw new FormError("Authorization code invalid."); } $r = $q->row_array(); $email = $r["recipient_email"]; $codeGt = $r["gamertag"]; // check valid gamertag $q = $this->db->query("select * from `users` where `gamertag` = '".$gt."'"); if($q->num_rows() > 0) { throw new FormError("Gamertag already exists."); } // validate gamertag /w inputted gamertag if(strtolower($codeGt) != strtolower($gt)) { throw new FormError("Gamertag Invalid"); } $this->_createAccount($email,$pass,$gt); // show register-thanks screen $this->load->view("register-thanks",$data); $success = true; } catch (Exception $e) { $data['error'] = $e->getMessage(); } |