veedeoo 474 Junior Poster Featured Poster

Hi,

Copy, paste to notepad, save as info.php, upload to your server.

    <?php
        phpinfo();

    ?>

Direct your browser to this file..

Look for the following setting values

        max_execution_time
        max_file_uploads
        max_input_time
        post_max_size

Let us know what you have..also what do you see on the

        Server API 

is it apache module or CGI/FastCGI?

veedeoo 474 Junior Poster Featured Poster

Double check your file extension.. or double check if your server supports short tags..My reasoning behind the short tags may not be allowed in your server is that, the only php codes showing on your screen shots are the part of your codes below the short tags.

veedeoo 474 Junior Poster Featured Poster

Hi,

When you run this script, is your computer connected to the Internet? If so, then we need to test your script outside the class. I am not sure if that class is even functional. Lets make a simple function that will load external xml file via cURL.

here we go...

        function loadThisXmlFile($url){

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)');  
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        ## store data as an output
        $output = curl_exec($ch);
        curl_close($ch); 
        ## load stored data 
        $xml = @simplexml_load_string($output);
        ## return output as an xml file
        return $xml; 

        }

to use the above function for testing do it like this..

    ## change the url to your own xml target
    print_r( loadThisXmlFile('http://feeds.bbci.co.uk/news/england/london/rss.xml'));

If all is well, then there should be some data showing on the page.

Let me know what you are getting after running the simple function I have provided above, so that we can move on to the next step..

veedeoo 474 Junior Poster Featured Poster

hi,

can you echo this in the same directory as your script and one in the image directory. Whatever comes up, that is your working directory and the image directory .

    basename(__DIR__) 
veedeoo 474 Junior Poster Featured Poster

@Mitch,

It could be just a url stuff and nothing serious. If you could output the other data off from the same file, maybe it is just the directory reference mishaps. Did you try

    ../images/

On your image's src?

Back to the case of smarty's iteration function.. I totally agree with all of you. I have no problem digesting whatever is posted here. Except for the odd implementation on the constructor.

For the template, LastMitch implemented the section loop instead of the foreach loop. So, it is pretty much capable of what the foreach can do.

    {section name=tbl loop=$book->title}

I preferred using dot notation though as much as possible, but it just only me :).

LastMitch commented: Yes, it was the URL all along +9
veedeoo 474 Junior Poster Featured Poster

Hi,

Do you mean from other server to your server?, or from server to your computer?

veedeoo 474 Junior Poster Featured Poster

Hi,

try chaging this

<select>

to this

    <select name="package">

So, when you do this

    $package = $_POST['package'];

The value of the selected item from the option is posted.

veedeoo 474 Junior Poster Featured Poster

you need to process the file first and then read... something like this, but you need to check if the form has been submitted..

    ## define target directory for you the uploaded file
    $file_directory = 'someDirectory';

    if(isset($_POST['submit']) && ($_FILES["file"]["error"] > 0)){

    ## move the uploaded file to your specified location, if there is no problem on submit
     move_uploaded_file($_FILES["file"]["tmp_name"], $file_directory .'/'. $_FILES["file"]["name"]);

     }
     else{

     echo 'No file uploaded at this time';

     }

     ## to read the file
     ## double check and make sure the file exist in file_directory, before opening it

     if (file_exists($file_directory .'/' . $_FILES["file"]["name"])) {
       ## put your text file reader function Here..
  }
veedeoo 474 Junior Poster Featured Poster

Hi,

copy and save whateverFileNameYouWant.php, upload to your server, and then direct your browser to this file..

<?php

phpinfo();

?>

Look for the following values, and they should have something more than 2MB at least 100MB or higher depending on your application

post_max_size
upload_max_filesize

If those above php.ini settings still on the default value you need to change them.. To change it, you need to ask your host. If you are testing it on WAMPP or XAMPP, look for the loaded configuration file on the page above..

Loaded Configuration File // this should have a value of /php/php.ini depending on your server setttings

If your host does not allow you modify your php.ini file look for the "server API" value of your server". Is it fast CGI? or is it Apache Module?

If it is CGI, FAST CGI, or anything with CGI. create a new file and save it as php.ini. paste codes below to this file

post_max_size = 200M
upload_max_filesize = 200M

Upload this file to the root directory of your server or your domain...CANNOT be in the same level as the public_html file.

If server API says, apache module.. create a new document on your notepad and save it as .htaccess

php_value post_max_size 200M
php_value upload_max_filesize 200M

WARNING! If you have an existing .htaccess file anywhere where the upload script is running, just ADD the above codes to it.

If you are running your script in LAMPPP or XAMPP just edit the php.ini …

veedeoo 474 Junior Poster Featured Poster

here is another one... :).

<?php

$string = 'abcd_23$_&';

if(!preg_match('/^[\w-]+$/',$string)){

echo 'oops! not a valid username';

}
else{

echo 'Valid Username'. $string;


}
veedeoo 474 Junior Poster Featured Poster

Here is the extended response proving both of the responses above :) are true.

<?php

function check_bool($value){

return ($value == 1 ? 'yes' : 'no');

}

$value = true; // this can be from database

## let us test the function above.

echo 'This shows a true value : <b>'. check_bool($value) .'</b><br/>';

echo 'This shows a false value : <b>'. check_bool('false') .'</b><br/>';

echo 'This given the value of 1 : <b>'. check_bool(1) .'</b><br/>';

echo 'This has value of 0 : <b>'. check_bool(0) .'</b><br/>';

echo 'This has value of "1" : <b>'. check_bool("1") .'</b><br/>';

echo 'This has value of "0" : <b> '. check_bool("0") .'</b><br/>';

echo 'This has an empty value : <b> '. check_bool(" ") .'</b><br/>';


## another way of utilizing the above function can be something like a comparator seen in c or java not like it, but serves like it ( now, I am confused which one is it really ???) :)

echo (check_bool($value) == 'yes' ?  '<b> Yes is the answer </b>' : 'No Way' );
diafol commented: show off! :) +14
LastMitch commented: Good Job! +7
veedeoo 474 Junior Poster Featured Poster

@lastMitch,

Here is an extremely simple example of inheritance where both the parent and the child has its own constructor.

Looking at the code, the parent does not even know that the child class exist. Only the child knows that the parent class exist.., and yes we don't have to let the parent knows whatever methods is being use by the child.

<?php

class Person{
        ## please pardon my shorthand approach. Normally, variable below are itemized for clarification.
        private $name,$lastName,$age;

        ## in older version of php, var was used instead and the constructor is not included. 
        ## However the first method should be named after the class name as in function Person().

        // var $name,$lastName,$age;
        //public function Person(){  return $name; }


        ## this is the constructor for the class Person 
        public function __construct($name,$lastName,$age){
            $this->name = $name;
            $this->lastName = $lastName;
            $this->age = $age;

        }

        public function get_name(){

        return $this->name;
        }

        public function get_info(){

            ## simple example of using another method of a class within another method within class ??????? :)
            return array($this->name,$this->lastName,self::get_age() );

        }

        public function get_age(){

        return $this->age;

        }
}

## extending the class Person above, child class can inherit all the properties of a parent class

class Info extends Person{

        ## this child class will inherit all the properties of the parent class.
        ## we can create a consructor here for this child class, and at the same time, must invoke the parent's constructor.

        public function __construct($name,$lastName,$age,$job,$hobby,$salary){

                    ## envokes the parent constructor
                    parent::__construct($name,$lastName,$age);

                    ## we only define things that …
veedeoo 474 Junior Poster Featured Poster

hi,

here is a demo I made, you can copy the source code if your want. Make sure the video ids are added as shown in the source code.

You cannot play all of them at the same time, but one at a time on click event. The most important about utilizing jquery is the ability to play video without reloading the page..

veedeoo 474 Junior Poster Featured Poster

let me add something, to make it a lot easier for you to grab the array output of a function without relying so much on the integer indexer, we can do it like this also;

<?php

function some_Array($name,$last,$address){
        $arrayItem = array();
        $arrayItem['name'] = $name;
        $arrayItem['last'] = $last;
        $arrayItem['address'] = $address;

        $output_Array[] = $arrayItem;

        return $output_Array;

}

$id = some_Array('poor','boy','north pole');

    foreach($id as $pos_id){

    echo 'Name: '. $pos_id['name'] .' '. $pos_id['last'];
    echo '<br/>';
    echo 'Location: '. $pos_id['address'];

    }
veedeoo 474 Junior Poster Featured Poster

try

$these_items = NewPos($mk_pos,$pos_member,$prev_num,$prev_loc,$type,$under_mem,$sent_id);
## loop through the output
foreach($these_items as $pos_id){

$position = $pos_id[0];
$follow_id = $pos_id[1];

}
veedeoo 474 Junior Poster Featured Poster

Hi,

Try adding...

if(isset($_GET['q'])){

## codes for the script response when GET is triggered
$q=$_GET["q"];
}

else{

$q = '';

}

Alternatively, I keep on seeing this type of approach by other developers of which I have not tested or ever tried, but I think it is worth teting for any vulnerability issues and weaknesses..

 if($_GET){

 ## codes here

 }
 else{

 $q = '';

 }

Again the alternative option is just too broad for my consideration. I am just assuming here that this method can fail.

veedeoo 474 Junior Poster Featured Poster

Hi,

This should not be too hard to do. You can start by writing a simple function to do the db insert, and then call this function or method whenever there is something to be inserted.

for example, we can create something like this..* WARNING! Script below is not tested. I just made this up to give you the general idea.*

    function insert_to_db($query,$filter,$table){
    $dbConnect = mysql_connect("localhost", "dBUserName", "$dbPassword");
    mysql_select_db($table);

    ## $filter is something that will trigger or sort types of events so that we can actually execute the query if any or one of the set condition/s has been met.
    #$db is the database connection

    if($filter = 'condition 1'){

    mysql_query($query);
    ## add your error checking and connection failed below
    mysql_close($dbConnect);

    }

    else{

    ## if you only have two $filters then else is appropriate to use. However, for multiple $filter, use else if or if else.

    mysql_query($query);
    ## add your error checking and connection failed below
    mysql_close($dbConnect);

    }

    ## you can either return it true or say something to acknowledged the transaction  OR you can return from within the if and else statements.
    return true;

    }

To use the function you will have provide the database query. Let's use the above function assuming that it has been tested and error free.

    $tableOne_query = "INSERT INTO Table_ONe(col_one, col_two, col_three) VALUES ('value_one',value_two','value_three')";

    $tableTwo_query = "INSERT INTO Table_Two(col_one, col_two, col_three) VALUES ('value_one',value_two','value_three')";

    ## now we can call our function above to do the dirty work..

    $insertTo_table_One = insert_to_db($tableOne_query,'condtion 1', 'Table_ONe');

    ## …
veedeoo 474 Junior Poster Featured Poster

Hi,

Can you try changing this part of your code,

 $fp = fopen($tmpName, 'r');

to

    $fp = fopen($tmpName, 'rb');

I suspect the time out is due to excessive memory usage which is caused by the fopen function trying to read a pdf file format as text rather than read as binary.. However, 'r' alone works on images to blob, so I am suggesting untested approach here just to give you a heads up :).

veedeoo 474 Junior Poster Featured Poster

Hi,

You need to run this simple script on your server

    <?php 
    phpinfo(); 
    ?>

First, look for the value of **Server API ** is it Apache module or apache handler?
Yes? You need to add this on your .htaccess file or create one if you don't have it.

    php_value upload_max_filesize 100M
    php_value post_max_size 100M
    php_value max_execution_time 1000
    php_value max_input_time 1000

No? What is it? Is it CGI or Fast CGI? If yes, create a new text document (preferrably on notepad) save it as php.ini file add codes below

    post_max_size 100M
    upload_max_filesize 100M
    max_execution_time 1000

Set your FTP program transfer mode to auto, and then upload the newly created php.ini file to the root directory of your site. Test your upload script.

Else? Contact your hosting support, and ask them to increase your upload limit and execution time for php script.

veedeoo 474 Junior Poster Featured Poster

I will give you another script to practice on later. Hopefully, I can test it by 3PM east coast time tomorrow.

For now, let me give you the thumbnail/imageProportioning class I wrote to demonstrate Singleton Pattern implementation in OO PHP.

Save this as ThumbIt.class.php.. we will be using this class to precisely create thumbnails.

<?php
## filename ThumbIt.class.php
## simple demonstration on how the singleton pattern can be use in OO PHP..
## written by veedeoo or poorboy 2012 , from daniweb.com ,phpclasses.org, tutpages.com, and yahoo php expert community.
## this script will be available in http://www.phpclasses.org/ and tutpages.com one month from now.

class ThumbIt{
   ## Singleton Pattern begins
   public static $instance = NULL;
   private function __construct(){
                ## if there will be another class needed by this class, you can create an instance here, else just leave this empty
            }
   public static function getInstance() {
                if(!isset(self::$instance)) {

                ## we create an instance of the class ThumbIt if there is no instance running
                  self::$instance = new ThumbIt();
                }
                return self::$instance;
              } 
    private function  __clone() {
      ## don't worry about this, just to make sure there is no clone going in the background.
    }

    ## end of singleton pattern
    ## class ThumbIt methods begins 
    public function createThumb($name, $maxW, $maxH, $image_path, $thumb_path, $outname) {

    $ext = substr($name, strrpos($name, ".") + 1) ;
    switch (strtolower($ext)) {
        case "jpg":
        case "jpeg":
            $img = imagecreatefromjpeg($image_path.$name) ;
            $size = self::ResizeMath($maxW, $maxH, $img) ;
            $size[0] = $maxW ;
            $size[1] = $maxH ;
            $img2 = imagecreatetruecolor($size[0], $size[1]) …
veedeoo 474 Junior Poster Featured Poster

Hi LastMitch,

Long time no see :). I have a few school days off.

Anyways, the form input type attributes are the following.. let see if I can them out of my head. I have not seen forms for quite sometime now.

text, hidden, submit, button, image, reset, checkbox, file, radio.. I think I missed a couple, but it is ok, you don't need it for this project.

In your case, the input type attribute will be text. So, in your codes above, we can change it to

    <form action="photoimage.php" method="post">
    Photo: <input type="text" name"" valve=" />
    <br />
    Caption: <input type="type" name"" valve="" />
    <br /><br />
    <input type="submit" name="submit" value="Submit" /><?php echo $msg; ?>
    </form>

Let me re-read my previous post on the link provided above. Normally, I don't remember codes I wrote, because I wrote them as I type my response.

LastMitch commented: Nice answer +2
veedeoo 474 Junior Poster Featured Poster

Hi,

Do you own the site? Yes -> use cache and save it as html file. No-> use HTML parser like simple DOM parser.

WARNING! Be careful when using DOM parsers. You can either ask permission from the site owner to harvest and save the data from their site..

Example code for cache method.. If you search my previous post, I posted a class for this.

<?php

ob_start(); 

include_once('contentPage.php');
## prepare for writing the cache file

    $filePointer = fopen('hardCopy.html', 'w');

    ## grab the output buffer and write it in cachefile
    fwrite($filePointer, ob_get_contents());

    ## close the file
    fclose($filePointer);

    ## Send the output to the browser
     ob_end_flush();

The above codes can and will work with cURL or simple HTML DOM parser. The hardCopy.html is the copy of the contenPage.php output as shown on the browser.

veedeoo 474 Junior Poster Featured Poster

Hi,

The problem with the codes are your variable names they are all the same. The script will only show the very last one, because it will override the first two. If you want it to work, then use .= (concatenating assignment operator) .

something like this..

$str_bodystyle = ""; //prevent any errors in php 5.3 and above.

$str_bodystyle .= str_replace("," ,"<br/>",$bodystyle);
$str_bodystyle .=str_replace("-" ,"&#45; ",$bodystyle);
$str_bodystyle .=str_replace(" - " ," &#45; ",$bodystyle);
echo $str_bodystyle;
veedeoo 474 Junior Poster Featured Poster

I am assuming here that the linked classes below are the same class you are currently using. Otherwise, please post any links for the source of the class as text file, but not to expect anyone downloading it.

Sorry about that Dude.. I just got busy to look at the full PclZip class at this moment. However, just by glancing at the script, there is a method called

 function extract()
{

Look for line 683 as shown here.
That's where you can add whatever you want.. I don't see any problem for you adding it or extending the class as you stated here. I am also assuming here that you are OOP expert.

Dude code to randomise is not the problem

Or, we can wait until someone extends that class for you.. I am hoping more volunteers will read this..

Next time, try to provide the link for the source code of the class you are using to prevent any confusion. Not all people are into using PclZip class. Like Class used, or this.

veedeoo 474 Junior Poster Featured Poster

Hi,

yOu can probably get by this using md5 ,uniqid, and rand combination like shown in the codes below. YOu can arrange your codes in such a way as

$filename = md5(uniqid(rand())).".".$ext;
$target_path = "YourDirectory/".$filename;
if(move_uploaded_file($file_tmp, $target_path)) {

## rest of your codes here

} 

Where? ext = to the actual extension of the file. So, you may want to get the extension first if needed, and then attached it to the filename.

veedeoo 474 Junior Poster Featured Poster

simple explantion on what is going in the server once the upload.php is submitted.

  1. PHP will save the files in the tmp directory. This is above the public directory e.g. public_html or htdocs.

  2. Once the files has been uploaded successfuly, the process.php will then execute the

    move_uploaded_file($_FILES['ufile']['tmp_name'][0], $item1);

coding convention of move_uploaded_file

 bool move_uploaded_file ( string $filename , string $destination )

**layman's terms **

MoveThisUploadedFile('FromTempFileDir/tempName','ToUploadsDirectory/AsNewFilename.WithTheExtensionOfTheFileAsAllowed').    
LastMitch commented: Thanks for the explanation, it was very helpful! +0
veedeoo 474 Junior Poster Featured Poster

@lastMitch,

Here is a sample script I posted months back. This one is a multi-file uploader, but you can easily remove the form elements that you don't need..

!DISCLAIMER! HTML is not my strongest area in any of the coding languages.

filename: upload.php

<html>
<head>
</head>
<body>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="process.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>multiple Files Upload </strong></td>
</tr>
<tr>
<td>Type Name:<input type ="text" name="poster"/></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>

filename: process.php . If will be processing single file upload, just remove the part where it is processing the 2nd and the 3rd file. That shouldn't be too hard to accomplished.

<?php
## deviced by veedeoo, and does not have any warranty of any kind.
## not intended in production server, UNTIL all possible security measures are implemented.

$poster = $_POST['poster'];
## define destination directory

define("DIR_","uploads/");

$item1= DIR_.$poster."_".$_FILES['ufile']['name'][0];
$item2= DIR_.$poster."_".$_FILES['ufile']['name'][1];
$item3= DIR_.$poster."_".$_FILES['ufile']['name'][2];


## use move_uploaded file function
move_uploaded_file($_FILES['ufile']['tmp_name'][0], $item1);
move_uploaded_file($_FILES['ufile']['tmp_name'][1], $item2);
move_uploaded_file($_FILES['ufile']['tmp_name'][2], $item3);

echo '<img src="'.$item1.'" width="150" height="150"><br/>';
echo "File Name :".$_FILES['ufile']['name'][0]."<br/>";
echo "File Size :".$_FILES['ufile']['size'][0]."<br/>";
echo "File Type :".$_FILES['ufile']['type'][0]."<br/>";


echo '<img src="'.$item2.'" width="150" height="150"><br/>';
echo "File Name :".$_FILES['ufile']['name'][1]."<br/>";
echo "File Size :".$_FILES['ufile']['size'][1]."<br/>";
echo "File Type :".$_FILES['ufile']['type'][1]."<br/>";


echo '<img src="'.$item3.'" width="150" height="150"><br/>';
echo …
LastMitch commented: Thanks for the script, it's very simple for me to understand! Thanks! +2
veedeoo 474 Junior Poster Featured Poster

just remove the id like this..

$sql = "INSERT INTO social (social, url) VALUES ('".
PrepSQL($varsocial) ."', '".
PrepSQL($varurl) ."') " ;
veedeoo 474 Junior Poster Featured Poster

Hi,

I have to re-read this question tomorrow. They just finished frying my brain at CALTECH all summer long :).

veedeoo 474 Junior Poster Featured Poster

Hi,

There is an online service called carbonite, that is the closest thing I could think of right now.

veedeoo 474 Junior Poster Featured Poster

Hi,

Try, removing the id in

$sql = "INSERT INTO social (id, social_media, url) VALUES (".
PrepSQL($varsocial_media) . ", " .
PrepSQL($varurl) . ") " ;

Auto-increment will take care of it for you.. the key here is that all column names you have in insert statement, MUST be matched in the values statement.

e.g. INSERT INTO someTable(colName1, colName2, colName3) VALUES('colVal1',colVal2',colVal3').

In my example above, I ignored the fact or the existence of the column named id, because if it is set to auto-increment, then mysql will do it automatically.

There is a big CASE of IF here, if the mysql data has been imported from another existing table, the id may have some lower limit and max limit on it. This is something to watch out in the future.

veedeoo 474 Junior Poster Featured Poster

Hi,

This code

if($_POST['formSubmit'] == "Submit") 

will eventually give you an error like .... error Undefined index: formSubmit, because it is not supported in newer version of php.

The most common and acceptable is

if(isset($_POST['formSubmit']))
{

## rest of your code here if the form has been set

}
veedeoo 474 Junior Poster Featured Poster

try rewriting

VALUES (\'$from\',\'$custname\',

to something like this..

 VALUES ('".$from."','".$custname."',

Do the same for the rest of it..

It is so easy to fall into this coding style

  {$from}, {$custname},

but that would be slower than just using concatenation operator . Using concatenation operator is a good practice, in eliminating any possible escaping problems..

e.g.

$thisString = 'Some string';

echo "This string". $thisString."<br/>";

echo 'This string '.$thisString.'<br/>';

## bad coding style below

echo "This string \'$thisString \'";
veedeoo 474 Junior Poster Featured Poster

all you need to do is to add the posted value to the old value which is in your cart session kind of like this. There are other ways of doing this, I am just showing you an example.

## this is your session before the submission
$before = $_SESSION['cart'][$pid];

## this is your newly posted quantity on top of what is already in the session

$addedNewQuantity = $v;
$newQuantity = "";

## add the added new quantity to your before
## you need to create a new condition if the customer is trying to add or remove
if($add){
$newQuantity .= $before + $addedNewQuantity;
}

if($remove){
## removing quantity , make sure the cart is not empty, so that is another environment you need to set.
$newQuantity .= $before - $addedNewQuantity;

}
## unset the session to reflect updated quantity
unset($_SESSION['cart'][$pid]);

## set the new session reflecting the new updated quantity
unset($_SESSION['cart'][$pid]) = (int)$newQuantity;
veedeoo 474 Junior Poster Featured Poster

Hi,

take this for your consideration... on your form method it show post. I am assuming here that the above script is called cart.php as shown in your form codes below.

<form action="cart.php" method="post">

<input type="hidden" name="action" value="update" />

while you are processing it as $_GET as shown on your codes in line 43

elseif(isset($_GET['action']) && ($_GET['action'] =='update')){

If possible, change the above to this

elseif(isset($_POST['action']) && ($_POST['action'] =='update')){

## then do the things they suggested here.

I hope I contributed something here, if not, I wish you good luck .

devianleong commented: Hi veedeoo , I had change to $_post and the error gone. But now the another problem is when I enter 2 in the quantity field and click update, the quantity still remain the same. Any solution ? +0
veedeoo 474 Junior Poster Featured Poster

there is a php function called reflection class as shown here, but never tried it.

veedeoo 474 Junior Poster Featured Poster

Hi,

I wrote something like this, but I am always hesitant to share it to general public, because there are some great security risks and vulnerabilties ,if not protected well enough against unauthorized entries.

veedeoo 474 Junior Poster Featured Poster

@rotten69,

I am using many different editors depending on what I have to work on. For instance, the above scripts I have provided in this thread was written on browser based editor, using my own php editor class in my portable xampp. I wrote this simple php editor class, so that I can write and test codes right away without the hassle of typing the url just to access the file. What is so cool about this php editor class? I can edit my php codes in browser environment.

For full php developement regardless of framework use e.g. code Igniter, cake php, and doophp , I normally use netbeans IDE php edition. I use it because of the smarty templating plugin for it. NetBeans IDE also have an auto error checking that can make the development process a lot easier. On top of this, I am using my own function and class finder just to make sure I can find the exact page where the functions or classes has been used or instantiated. The Netbean built-in search function is kind of slow, so my solution is to write my own search script that is fast enough to find functions, variables, class in all the files within specified directory.

For android related apps and simple Java, I use eclipse.

For simple and fast coding I use either notepad++ or PHP designer 2007 personal free edition. For the initial writing of the codes, I use the notepad++ first and then to debug …

veedeoo 474 Junior Poster Featured Poster

Alternatively, we can use this class to create and include cache files. Although it i s a longer version of the above, this class can be extensible and reusable as many times as you want.

save this as cache.class.php

<?php
## Written and provided to you by Veedeoo or PoorBoy 2012
## this class has no warranty of any kind.
## feel free to use this to your application as needed
## feel free to extend this class for improved and better functionalities.
## What I meant by improved and better functionalities? Function like compression of cache file e.g. gzip.


    class MakeCache{

        private $content= null;
        private $cacheDuration = null;
        private $cacheLoc = null;
        private $cacheFile = null;


        public function __construct($content,$cacheDuration,$cacheLoc,$cacheFile){
         $this->loc = $cacheLoc;
         $this->file = $cacheFile;
         $this->duration = $cacheDuration;
         //$this->comp = $cacheCompression;
         $this->content = $content;

        }

        private function checkDuration(){
            return(file_exists($this->loc."/".$this->file) && (time() - $this->duration < filemtime($this->loc."/".$this->file))? true : false); 
        }

        public function useCache(){

         if(self::checkDuration()){
             ob_start( );
        include( $this->loc."/".$this->file);
        $this->output = ob_get_clean( );

        }
            else{
                ob_start(); 
        ## include the page to be cached
        include ($this->content);

        ## prepare for writing the cache file
        $filePointer = fopen($this->loc."/".$this->file, 'w');

        ## grab the output buffer and write it in cachefile
        fwrite($filePointer, ob_get_contents());

        ## close the file
        fclose($filePointer);

        ## Send the output to the browser
         $this->output = ob_end_flush();
            }

            return $this->output;
        }

    }
    ## end of class
?>

You can call this class from any page..for example

<?php

include_once 'cache.class.php';

## instantiate the cache class

$showCache = new MakeCache("reporst.php", 10080 * 60, "cache","reports.html");

## print …
veedeoo 474 Junior Poster Featured Poster

@jemz,

html5 players does not support wmv, because it is a browser based player. So, the most commonly supported video formats or extensions are mp4/h264, ogv or ogg, webm.

If you are wondering which format is the most useful, without the burden of having too many duplicates of the same video encoded in different formats? My choice would be the mp4/h264.

Why mp4/h264 ? Because it is supported in html5 and apple gadgets.
Will all the browsers wil be able to render mp4/h264 video? the answer is yes and NO. Yes, because it supports many mobile browser. No, because firefox and apple only supports it. However, you can always write a fallback player codes, so that whenever a browser is not supporting mp4/h24 video, we can fallback to regular flash player like flowmotion or jwplayer. That should make everyone happy. The most important about using mp4/h264 encoded video is that it can be encoded in the very minimum bitrate and still the quality is far superior than any other video formats.

Downside of mp4/h264? The downside is that you cannot pseudostream this type of video, because the moov atom of this video is located at the tip of the video file. Ok..ok. yes, we can pseudo stream mp4/h264 video by using php script written by some video afficionados like myself. I will not be providing the script for it, because I am relying on it heavily to pay for my coffeee.

How do you encode mp4/h264 videos? I can …

veedeoo 474 Junior Poster Featured Poster

Hi,

Here is simplest way of doing this (it is too simple that my comments out numbered my actual codes :)). Of course, you must search more on how to improve this. I am in the assumption here that file you are trying to cached is in your server. If it is coming from the external server, then process is slightly different than processes my sample codes will do.

Step One: in your server, create a directory called cache, and give this directory a permission CHMOD of 777 or 755 depending on your host's recommendation.

Step Two: copy codes below and name it anyNameYouWant.php.

<?php
    $cachetime = 10080 * 60;
    ## page naming can be anything it is all up to you
    $pageName = "somepage.html"; 
    $cachefile = "cache/".$pageName;

if(file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile)))  {


    ## the page has been cached from an earlier request

    ## output the contents of the cache file

    include($cachefile); 

    }
else{

    ## we need to include a fresh file or the actual file where we can generate the cache file
    ob_start(); 
    ## include the page to be cached

    include 'pageToBeCached.php';

    ## prepare for writing the cache file
    $filePointer = fopen($cachefile, 'w');
    ## grab the output buffer and write it in cachefile
    fwrite($filePointer, ob_get_contents());
    ## close the file
    fclose($filePointer);
    ## Send the output to the browser
ob_end_flush();
echo "cache file created";

}
?>

Instruction for modification.

1.$cachetime = seconds * 60 ... gives you the time expiration before a new cache file is generated …

SummerNight commented: great answer! +0
veedeoo 474 Junior Poster Featured Poster

Hi,

First, can you please let us know the format of these videos? Depending on the format, requires different player.. e.g. flash for flv and mp4/h264, divx player for divx and avi, and the list goes on...

veedeoo 474 Junior Poster Featured Poster

Hi,

Not exactly though, you can insert them inside your class and call them within the class. This way you will only have to call one or two methods outside your class. That's the reason why I set its visibility to private on my exmaple.

You can also retrieve the methods returned data as an array if you wish to do so.

for example,

    public function doSomething(){
    $this->error = "";
    if(SomeCondition){
    $this->error ="condition A error";

    }

    else{
    $this->error .= "condition B error";
    ## otherwise error is set to default as empty

    }
    ## say, we want to call helper methods here to validate something, then we can do so by just using the self::doSomethingElse().
    ## example..
     if(!self::verifyEmail($email)){
$this->error .= "email is not a valid email address";
}
else{
$this->email = true;
## you can either insert to database or just return the boolean true above.
$this->error .= "email has been added";
}

## return the array from this method, for other methods to utilize

return array($this->error, $this->email);

}

and then, within the method utilizing the method above can be coded like this. This will and can be use outsde this class, whenever the class is instantiated anywhere in your site.

 public function getAllValidation(){
 $this->emailHelper = self::doSomething();
 $this->otherThings = self::functionOfOtherThings();
 $this->someOtherValidations = self::functionToValidateOtherThings();
 ## extract the data returned by doSomething.
 $this->error = $this->emailHelper[0];
 $this->validation = $this->emailHelper[1];

 ## extract the rest of the helpers 

 ## do some other things here..

 ## return all validations as an array.. it can …
veedeoo 474 Junior Poster Featured Poster

To use it within your class, you can pretty much do it like this.

 $email=  strip_tags($_POST['email']);
 if(!self::verifyEmail($email)){
 error = "email is not a valid email address";
 }
 ## we can also clean up the message using the helper function like this

  $message =  strip_tags($_POST['message']);

  return trim(self::sanitizeString($message));

There are many more ways I could show, but my keyboard is acting up again.

veedeoo 474 Junior Poster Featured Poster

Hi,

You can also use php filter_var function. I keep on forgetting about this function. You can use this function in your helper method.

Something like this..

private function verifyEmail($email) {

 ## returns true or false
return filter_var($email, FILTER_VALIDATE_EMAIL) && preg_match('/@.+\./', $email);
}

private function sanitizeString($tstring){
 ## this method will be use by others within the class

return trim(filter_var($tstring, FILTER_SANITIZE_STRING));  

} 
private function sanitizeUrl($url){
return filter_var($this->url, FILTER_SANITIZE_URL);
}
veedeoo 474 Junior Poster Featured Poster

Hi,

What is your php/text editor? try using notepad++ or php designer 2007 personal edition. Both are free at cnet.

To fix it you really need to read line by line and try sorting it really well and add carriage return where it is needed.

veedeoo 474 Junior Poster Featured Poster

Hi,

Just bring down the comment tags. One more thing multi-line comment in php should be like this

<?php

/* beginning of long comments from the author



*close the comment tag below

*/
veedeoo 474 Junior Poster Featured Poster

you can also give this a try. Just use your command prompt type in the options, the location of the php files or project, type the output file e.g. file.exe , and you are good to go.

You can also add an icon for your converted executable php..

Downside?
The downside is that you will have to distribute some dll files needed by your application e.g. curl dll.
It does not support php 5 and above.

Security?
Watch out for the php function RecursiveIteratorIterator.. I strongly advice you to stay away from using this, unless you have a really good intention behind your application.. would not elaborate on this, but I could already see where the endusers can be exploited by this type of application..

here is a good one... just a tiny snippet of this vulnerability

  <?php
    $dir = new RecursiveIteratorIterator(
     new RecursiveDirectoryIterator('/',true)
    );

    foreach($dir as $file){
        echo $file->getPathname(),"\n";
    }
?>

You run the script above, and you will see what are the things exposed from the enduser's files. Enduser files are exposed including the sitemanager.xml file for filezilla...

Watch out for what you wish for.....

veedeoo 474 Junior Poster Featured Poster

Does the smarty compile the header.html?
Anything inside the directory themes_c?
Can you turn on the debug to true?

veedeoo 474 Junior Poster Featured Poster

@lastMitch,

I did not know, that it was almost midnight when I responded on this thread. Anyways, I managed to write some simple script to make you edit php, html, css, js files right in your admin area..

I wrote a single class for this, but it needs an upgrade at the moment, so before heading out for school today, I managed to write a simple script that will do as what you need.

Please Protect this script from public access at all cost. I strongly suggest using .htaccess protection on top of the login credentials as admin. NEVER and DO NOT allow any members of your site (if any) to access this script.

I did a test run twice.. and I can confirmed that it is working on my side. The only thing that this file don't have is the fancy highlight capabilities, and systax validation.

Here we go...

sTep ONe.. save this file as stepone.php.. or any name you want will do just as fine..

<?php
####  WARNING! THIS SCRIPT MUST BE PROTECTED FROM PUBLIC ACCESS ###########
## written by veedeoo or PoorBoy 2012
## feel free to use at your application.
## filename : stepone.php


## first we define our file extension allowed. 
$ext = array('.php','.html','.js','.css','.tpl');
## we define our current working directory where the dumper should be looking for files.
$work_directory = getcwd();

## we create a file dumper function
function dump($dir,$ext) {

$d = dir($dir);
while (false!== ($file = $d->read()))
{
$extension = substr($file, strrpos($file, …
LastMitch commented: Thanks for hard work! You made my day! =) +0