veedeoo 474 Junior Poster Featured Poster

I know this thread has been marked solved, but I think it is worth mentioning that I was able to recreate your problem.. For PDF to blob, PDF should be at least below 5MB and 10MB is the maximum threshold in MYsql (InnoDB storage engine.. again I believe this is server setting dependent, but in local server it is just too difficult to predect or observe the actual minimum and maximum), OR ELSE you will get the "mysql have gone away error"..

In the upload problem, it is not really happening after you set up your maximum upload file size, the problem seems to be on the fread.. retrieving the pdf file from the PHP temp directory.. this is where the process tend to fail.

I was able to do comparison between the fread and file_get_contents to handle the uploaded PDF file just for the purpose on converting it to BLOB data. However, the processing problems remains the same.. script timed out everytime the PDF file size exceeded the 10MB threshold.

My suggestion is to ONLY allow PDF file size of less than 2MB if this script is going to be running on the production server. Server resources must always be put into consideration at all times.

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,

We cannot directly re-create or generate a youtube id for this matter, because youtube is using a simple yet very effective method of generating video ID. It is so simple that you already done it on your script. However, the hardest one to match is the output of something that has no alogarithm at all. It is pretty much divided into to three random arrays to create dashes, caps, lower case, and numbers. So, the randomness can be something like this generate dash,generate random 2 upper case letters, generate 2 or single integers followed by random lowercase, generate the mix of the three in random. Then this ID is then match to the database if ever exist and if it does not, that becomes a unique ID. Unlike other video sharing website e.g. p**nhub ( it is not that I like visiting this type of site, but I was envolved in developing an id snipper script for this), which is pretty predictable.

How do I know all about these? Because my older brother Michael went to school and used to work with one of the founder of Youtube way back in the early years of paypal. Inspite of the change of ownership which is now google, I still believe that the video ID generator function has not changed at all or maybe at the very minimum to this date.

The easy method I used in my demo link is to use my minified version of the youtube API class …

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 aplogize for the interruption. Is this what you're trying to achieved? Click Here. That's random video from youtube with at least 99.00% accuracy.. of course, the remaining 01.00% can be given to the script load error.

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,

Which document did you edit?
Is it the apache\conf\httpd.conf?
How was the modified entries added ? formatting wise ..e.g DocumentRoot "/xampp/theOneYouAdd"

Default value for XAMPP
DocumentRoot "/xampp/htdocs"

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,

Did you try adding a name atribute in your <option>? Like this..

   echo '<option name= "title" value=" '. $row['title'] .' ">" '. $row['title'] .' "</option>';   

Your query can be modified to something like this..

$query = mysql_query("SELECT * FROM REVIEW WHERE title = '". $_POST['title'] ."'");

!WARNING! Be careful when adding form inputted data in your database, make sure to sanitize these data.. otherwise your site will be highly vulnerable.

Don't use fetch as your variable name.. this variable name can and may have a naming colision issues later on. There are many PHP reserved words that we should avoid. Use $row instead. I know the $fetch is not an actual reserved words, but FETCH does.. it is safer to just stay away from them, rather than getting at them at close range.. I hope you understand what I am trying to say...

Like ..

while ($row=mysql_fetch_assoc($query)){

Don't use this

<p>Title:<input type="text" size="35" name="title" value="<?php echo $_POST['title']; ?>"></p>

and use this instead..

<p>Title:<input type="text" size="35" name="title" value="<?php echo $row['title']; ?>"></p>

Do the changes for the rest of your codes.. and if you want to update your database base on the inputted values from the form, then you must add another form above your query..

something like this...

if(isset($_POST['select'])){
 echo '<form name="updateFor" action="post" method="update.php">';

 ## put the rest of your codes here..



 } // this must be the end of your while loop

 ## add the submit form input

 echo '<input type="submit" name="update" value="update">'; …
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

@gacoekchip.pokher

If you just want to add the text string in column "message" of table "b_table", then you can prepare your query like this... not the most efficient, but I want to leave some space for you to experiment in these very important aspects of PHP and MySql.

To Select phone and group from "a_table", we can prepare our query as simple as this.

$query = ("SELECT * FROM `a_table` WHERE `phone` = '". $phone ."' AND 'group' = '". $group ."'") ;

After getting some result ( I strongly suggest to use mysql_num_rows), then perform an "update" query. In your case , the update query can be like this,,

$query = ("UPDATE b_table SET amessage ='". $message ."' WHERE phone ='". $phone .'") ;

IMPORTANT! If you just need to update, then single statement may suffice. Use query below instead.

 $query = ("UPDATE b_table SET amessage ='". $message ."' WHERE `phone` = '". $phone ."' AND 'group' = '". $group ."'") ;

There you have it :)

veedeoo 474 Junior Poster Featured Poster

Hi,
!WARNING! EXAMPLE script below, does not have any security protection of any kind. Please read or search more about security measures in PHP. Most importantly, if mysql is involved. DO NOT USE example below in production server.

I consider myself as a newbie in coding java . The last time I wrote an application using this language was more than one and half years ago. It was about donwloading youtube videos using java, because there is no way it can be done in php alone. So, I am pretty rusty. However, I can probably help you with the php .

So, I am in the assumption here that you are extremely familiar on how to instantiate your java class within the php script, and your server is also equiped with the PHP/Java bridge or whatever dll files are needed. I am not sure about this though, because of the reasons I already stated above.

Assuming that we have this as given,

mywebsite.com/sethighscore.php?secretkey=23234234&user=bob&itemscollected=45&timeplayed=1hour

then our php code to grab those pertinent information can be as easy as

## let's start as session for the time reference
session_start();

## let us assume that in the beginning of the play, the time is when the user landed on the play page, or for whatever method we can derive from the java application.

## the time of the page visit is held constant in the session
$_SESSION['begin'] = time();



if((isset($_GET) && ((!empty($_GET['user']) && (!empty($_GET['itemscollected'])){

## we know the secretkey is wrapped within …
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

Hi,

You can also try this code.. if it does not work in your server settings, you need to use cURL to fetch the xml file off google. For now, let's try this first.

This is just one of the three methods we can parse xml DATA... Pretty much the lazy approach, but it is more of a direct fetch. The foreach loop is at the minimum, unlike other methods where loops are within loops.

<?php

$final_addr = '1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA';
$someXML = ("http://maps.googleapis.com/maps/api/geocode/xml?address=".$final_addr."&sensor=false");

  $doc = new DOMDocument();

  ## if this one does not work in your server environment, you MUSt use cURL to fetch someXML

  $doc->load($someXML);
  $thisMap = $doc->getElementsByTagName( "GeocodeResponse" );
  foreach( $thisMap as $address )
  {
  $latValue = $address->getElementsByTagName( "lat" );
  $lat = $latValue->item(0)->nodeValue;
  $longValue = $address->getElementsByTagName("lng");
  $long = $longValue->item(0)->nodeValue;

  echo "<p>Lat: ".$lat."</p>";
  echo "<p>Long: ".$long."</p>";
  }
  ?>
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

Can you please give us some codes or the actual data posted in your database table.. e.g. embed codes, and the php responsible for posting and playing the video on your page.?? Because 403 error can be as simple as url directed to directory.

veedeoo 474 Junior Poster Featured Poster

how is your error_reporting set in your xampp php.ini file??

sample error reporting on php.ini file . NOtE! error_reporting = E_ALL ^ E_STRIC has been deprecated some time ago and the E_ALL is the one takes the helm from php 5.4

error_reporting = E_ALL

for the php page, you can also add this on top of the page. If you find editing php.ini file is not within the scope or your espertise, then it can be defined on top of the page before anything else.

 error_reporting(E_ALL);

For more info. on error reporting settings and options, please visit php.net.

veedeoo 474 Junior Poster Featured Poster

Hello everyone,

!WARNING! this function should only be use, WHEN ffmpeg PHP CANNOT be installed in the server.

I just got some free time from tedious and hectic school schedules. About two months ago, I saw a question about "how to get the duration of a given video file?". Of course, the common response to this question is to utilize ffmpeg php.

Using the ffmpeg php extension, we can pretty much grab anything from all sorts of video extensions. For example, we can implement simple codes below to get the duration of a video file..

$thisVideoFile = new ffmpeg_movie("video.ext");

echo $thisVideoFile->getDuration();

The code above is that all we need to get and display duration of the video. Pretty easy huh? "Wait a minute, I don't have any ffmpeg installed on my server, what shall I do?" one developer screamed with disperation. Well, in response to the screaming developer's question is not that hard to guess??? Of course, it can be done with pure php, and this is how I did it...

Once again, I would like to WARN everyone that this equation or formula is sometimes off by 0.001 micro seconds. This is not an ultimate solution, but rather an easy fix when there is no FFMPEG php installed on the server.

function getDuration($file){

if (file_exists($file)){
 ## open and read video file
$handle = fopen($file, "r");
## read video file size
$contents = fread($handle, filesize($file));

fclose($handle);
$make_hexa = hexdec(bin2hex(substr($contents,strlen($contents)-3)));

if (strlen($contents) > $make_hexa){

$pre_duration = hexdec(bin2hex(substr($contents,strlen($contents)-$make_hexa,3))) ;
$post_duration = …
cereal commented: great work! +8
LastMitch commented: Nice Work! +0
veedeoo 474 Junior Poster Featured Poster

I really don't see any problem with the database migration to your own cms script, as long as you maintain the same database query used by the tomato..

AND as long as you know the database structure, you should not have any problem in doing any CRUD on it..

veedeoo 474 Junior Poster Featured Poster

HI,
You need to ask the 000webhost what is the limit file size for upload. By default, the limit is somethere below 32MB. If your file size is more than the default value, the upload will just eventually terminate without warning or notification.

try saving this as filesize.php

 <?php

 $thisMax = ini_get('upload_max_filesize');

 echo $thisMax;

 ?>

that should give you the max upload file size limit setting of your server. Because of the nature of your hosting account, I doubt it we can do anything to increase the max size.

veedeoo 474 Junior Poster Featured Poster

The problem maybe in

".$row["website"]."

it should be something like this

".$row['website']."

However, I just realize that my argument above, may not be feasible. Until, we are sure that the $row['website'] really exist in your database.

What is the value of the column website on your database?

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,
ADDED LATER: MY post is late, so please consider diafol's response before this.

This is just a humble suggestion for your script. Why not use a unix timestamp instead of the actual human readable date.

For example, an account can have a date verification expiration two days from the date it was sent to the user. Both beginTime and expiry must be stored in the database.

  ## get the current time when the expiratio starts ticking.
  $beginTime = time();

  ## expire this in 1 day from the curTime above.
   //$expriry = strtotime('+1 day', $beginTime);

  ## we can use the above expiry or below..

  $expiry = strtotime("+24 hours", $curTime);

  ## now we can approximate if the expiry time has been exceeded or not.

  if(time() >= $expriry){

  echo "oops, your activation noticed had expired";

  }

  else{

  echo "Your ok..";

  }

The $beginTime above refers to the time recorded, when the expiration begins to countdown. The time() in the if statement is the current time, when the user access the account for activation.

veedeoo 474 Junior Poster Featured Poster

Hi,

I must have posted answers to this type or related question in the past. Here we go again take Four.. I want to do this my way, or we can just take the highway..

First, we create our new books.xml file

<?xml version="1.0" standalone="yes"?>
<books>
  <book>
  <author>Poor Boy or veedeoo</author>
  <title>Hacking is Bad</title>
  <publisher>the black book</publisher>
  </book>
  <book>
  <author>veedeoo</author>
  <title>The Secret of Hacking for Revenge</title>
  <publisher>the black book</publisher>
  </book>
</books>  

Second, we create the php script responsible for writing and displaying the changes made on the books.xml file. Let's call this as book.php .

<?php
    ## filename : book.php

    $xml = "books.xml";
    $doc = new DomDocument;
    $doc->Load($xml);

        $books = $doc->getElementsByTagName('books')->item(0);
        ## we iterate  book block
        $new_BookEntry = $doc ->createElement('book');
        ## items going inside the book block
        $new_AuthorEntry = $doc->createElement('author');
        $new_TitleEntry = $doc ->createElement('title');
        $new_PubEntry = $doc->createElement('publisher');

        ## prepare items to be added in xml file

        $authorNode = $doc ->createTextNode ('New Book');
        $titleNode = $doc ->createTextNode ('New Title');
        $pubNode = $doc->createTextNode ('new publisher');

        $new_AuthorEntry-> appendChild($authorNode);
        $new_TitleEntry-> appendChild($titleNode);
        $new_PubEntry->appendChild($pubNode);

        $new_BookEntry-> appendChild($new_AuthorEntry);
        $new_BookEntry-> appendChild($new_TitleEntry);
        $new_BookEntry->appendChild($new_PubEntry);
        $books -> appendChild($new_BookEntry);

if($doc->save($xml)) echo "Sucess";

## read updated xml file

 //$doc = new DOMDocument();
  //$doc->load( $xml );

  $records = $doc->getElementsByTagName( "book" );
  foreach( $records as $record )
  {
  $author = $record->getElementsByTagName( "author" );
  $author = $author->item(0)->nodeValue;

  $publishers = $record->getElementsByTagName( "publisher" );
  $publisher = $publishers->item(0)->nodeValue;

  $titles = $record->getElementsByTagName( "title" );
  $title = $titles->item(0)->nodeValue;

  echo "<p>Title: ".$title."<br/>Author: ".$author."<br/>Publisher: ".$publisher."<br/></p>";
  }

?>

That's should do it..direct your browser to book.php and you should be able to read …

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

Hi,

This is not a direct response to your questions. I can rewrite your entire codes to make it functional if I want to. However, I don't want to deprive people from the wonders and benefits of learning.

Below is the simplest SAMPLE codes I could come up with inheritance. In fact, I have created two child classes.

<?php
    class Member{
     ## you can use these 
        //var $name= null;
        //var $lname = null;
        //var $age = null;
        //var $sex = null;

        ## or set them as public
        public $name= null;
        public $lname = null;
        public $age = null;
        public $sex = null;

        ## if you don't want a constructor in the child class, then you can include all variable above as an arguments below.
        public function __construct($name,$lname,$age,$sex){
            $this->name = $name;
            $this->lname = $lname;
            $this->age = $age;
            $this->sex = $sex;
        }

        public function getName(){
            return $this->name;
        }

        public function getlname(){
            return $this->lname;
        }

    }

    ## extend the parent class above without the constructor
    class Age extends Member{


        public function getAge(){
         return $this->age;

        }
    }
    ## extend the parent member class above without constructor
    class Sex extends Member{
        public function getSex(){
            return $this->sex;
        }
    }

    ## instantiate the child class Age
    $membersAge = new Age('Name','lname','20','male');

    echo "Age: ".$membersAge->getAge()."<br/>";

    ## instantiate the child class Sex
    $memberSex = new Sex('Name','lname','20','male');
    echo "Sex: ". $memberSex->getSex();

    ## instantiate the parent
    $membersData = new Member('Name','lname','20','male');
    echo "<br/> Name: ".$membersData->getName()."<br/>";
    echo "Last Name: ".$membersData->getLname()."<br/>";
?>

In contrast to some beliefs, Yes you can process $_GET, $_REQUEST, and …

veedeoo 474 Junior Poster Featured Poster

Also, I would like to remind you that a coding technique like this in OOP is awfully bad.

$someVariable = $this->variable;

More acceptable is like this

$this->variable =  $someValue;

Although there is nothing wrong with that and the script is still functional, there are so called silent standards among coders that this type of scripting style should be avoided at all cost first, before you can actually code it like that. Of course, if there is nothing we can do to avoid it, you must type a comment above it.. I was almost got disowned by my family, when i wrote my code like that years back .

 ## this cannot be avoided and it is awfully wrong
 $this->variable = $this->variable;

another cool techniques or methods in coding in OOP are the setters and the getters... like

  private function setThis(){

    ## return output for the getter
    return $this->output;

    }

  public function getThis(){

  return (self::setThis());

  }

so, If you anticipating that the items in the data array is going to be used by other methods within the class or by the child class it should not be included in the constructor, so that you can redefined it somewhere else.. for example if it will be in the child class, let it be defined within the child class properties and then in the child class constructor, after the parent constructor has been declared.

veedeoo 474 Junior Poster Featured Poster

I just have one question for you, before I get involved in this question. In your codes, you have extended class BasePersonal..

and in your child class Personal you have

class Personal extends BasePersonal
{

## where is the constructor of your parent class??
## it should  be here?

if you want to get the output of a method from the same class, like in your codes should be at least modified to something similar to the codes below..

 public function getDataInArray()
{
$data = array();
$data['user_id'] = $this->user_id;
// $data['Firstname'] = $this->full_name;
$data['sex'] = $this->sex;
$data['birth_date'] = $this->birth_date;
$data['relationship_status'] = $this->relationship_status;
$data['country_id'] = $this->country_id;
$data['zone_id'] = $this->zone_id;
$data['occupation'] = $this->occupation;
$data['about_me'] = $this->about_me;
$data['what_i_do'] = $this->what_i_do;
$data['what_i_go'] = $this->what_i_go;

$thisOutputData[] = $data;

return $thisOutputData;
}

Just a side note,... you can define your visibility of the method getDataInArray as private.

To access the array from the above output by antoher method, it should be written like this we don't need the data as variable in the method saveDataInArray

  public function saveDataInArray()
{
## lets harvest or dump the data from the method above.
$newData = self::getDataInArray();

foreach ($newData as $data){
//$this->full_name = $data['full_name'];
$this->sex = $data['sex'];
$this->birth_date = $data['birth_date'];
$this->relationship_status = $data['relationship_status'];
$this->country_id = $data['country_id'];
$this->zone_id = $data['zone_id'] == '' ? null : $data['zone_id'];
$this->occupation = $data['occupation'];
$this->about_me = $data['about_me'];
$this->what_i_do = $data['what_i_do'];
$this->what_i_go = $data['what_i_go'];

## I am not sure about the this->save() method below.
///$this->save();
}
}

I commented the this->save() in …

veedeoo 474 Junior Poster Featured Poster

try

echo '<link rel="stylesheet" type="text/css" href="style.css" />';
veedeoo 474 Junior Poster Featured Poster

This method

 getDataInArray()

is it a method from the same class? If so, it should be coded like this

 $personal->personal= self::getDataInArray();

Try using the parent and self thing so that it does not give you any confusion during future edits..

veedeoo 474 Junior Poster Featured Poster

In practice, holes and vulnerabilities of php script becomes probable the moment you type something between the tags below. Before you ventured in writing codes, keep this in mind at all times.. php has a bad twin brother and is equally powerful as php, and this brother's job is to hack anything written in PHP.

<?php   
## All codes below this line, you must protect at all cost. It is your responsibility, and NOT your users..
?>

These vulnerabilities will be escalating in uprecedented rate, when you are not careful. You cannot just let your guards down, whenever you are typing on your code editor. YOu must test everything, before making it available for public access.

PHP is almost synonym to vulnerabilities as windows is almost synonyms to trojans and viruses. However, due to careful programming designs and more attention to detail in security issues, windows users still exist and continue to grow exponentially on a daily basis. The same careful steps and attention to detail in security can be applied, while you write your php program.

Vulnerabilities in php are mostly created by the programmers themselves, but on the other hand we cannot put the blame on them 100%, because it is not easy to protect your codes as you write them. System administrators are also have the sacred responsibilities on updating the server's php version and many other things needed to run a more security friendly servers.

pHP have built-in validate filters and

veedeoo 474 Junior Poster Featured Poster

Hi,

As far as I know, maybe I am wrong on this, but we cannot invoke the parent's parent's constructor in the grandchild's class... ( we could but it is really tricky,,, and that is not commonly used).

here is a simple enheritance with the invoked constructor in the child. WARNING! This class may have error. I just type it here without testing it. I don't have any chance to run it, because it is already late.

This is still normal

<?php
    class One{
     private $one = null;
     private $two = null;

     public function __construct($one,$two){

        $this->one = $one;
        $this->two = $two;
    }
    public function getOne(){
        return $this->one;
    }

    public function getTwo(){
        return $this->two;
    }
}
## end of class one
    ## child class two begins

    class Two extends One{
     private $three = null;

     public function __construct($one = null,$two = null,$three){
         parent::__construct($one,$two);
        $this->three = $three;
    }

    public function getThree(){
        $total = $this->three + (parent::getTwo());
        ## this should return integer 5
        return $total;
    }

    }
    ## end of class two



$newObject = new Two(1,2,3);

echo $newObject->getThree();

?>

Notice the above class Two it invokes the parent's constructor. Now, it will be too easy for anyone to assumed the class two can be extended, but wait a minute.. everything we have established in grandparent class will not be there in the grandchild.

For example, If I extend the child class above, it will become a parent and its parent will become the grandparent, so the arguments in the grandparents constructor is not …

veedeoo 474 Junior Poster Featured Poster

Hi,

Do all things they suggested above, and then search amazon for books in php if possible look for something that will include introduction to OOP for non-programmers.

!NOTE! do not memorize means to understand the logic behind the subject matter. Learning does NOT always equates to understanding, but understanding is always a proof of learning.

The main key points of learning to program is to be familiar with the syntax, functions, and reserved words and variables.

  1. Read www.w3school.com tutorial on php. DO NOT memorize anything! just read them whenever you feel like reading comfortably.

  2. As you move along the chapters, follow examples by actually writing it on your own and running it own your server. For example, if you are learning how to echo string or variables, you need to do this exeercise on your own.

  3. Read and learn (but do not memorize) all the loops in php, and practice using all of them by actually writing your own script. Write your own example using for, while, foreach loops.. these are commonly use in php and other programming languages.

  4. Read, learn and practice on php conditional statements e.g. if,else, ifelse.. AND the php operators e.g. =,==,<=,>=, +,++... Common usage using the conditional statement if and operator

    if($something == "something"){
    do this;
    }

  5. Read, learn , practice form processing using php by using the following $_GET, $_POST, (not recommended but it is worth experimenting) $_REQUEST. YOU MUST write your own codes for this..

  6. Read, learn, practice …

veedeoo 474 Junior Poster Featured Poster

yes, if you have the video in your server. ffmpeg is needed to create thumbnails.

Based on the resolution of the video itself, we can determine what would be the final dimension of the image. In order to do this, you need the latest ffmpeg distro installed in your server AND the ffmpeg php .

Upon successful installation of the ffmpeg with all of its required packages and plugins, and the ffmpeg php, we can easily determine pretty much all of the information about the video..

For example, we can use simple codes below to extract some important data about the video

  ## we can open the video as an object
  ## we don't want it as boolean persistent

  ## we set dimension as null at first
   $thisVideoDimension = null;

  if($veedeoo = new ffmpeg_movie('uploads/yourVideo.mp4'){
  ## the media is a valid and supported media
$thisMedia = true;
## we get the dimension of the video from the veedeoo object

$thisVideoDimension = array($veedeoo->getFrameWidth(),$veedeoo->getFrameHeight());

}
## we do a simple check if the width is greater than 480
## we can always use the long form of if statement, instead of a short hand as shown below.

$thisWidthForHD = (($thisVideoDimension[0] > 480) && ($thisVideoDimension[1] > 380))? true : false;

## now based on the response from thiswidthforHd, we can construct our encoder.

if($thisWidthForHD){
## hd thumb
$thumb = (PATH_OF_YOUR_FFMPEG." -y -i uploads/yourVideo.mp4 -f mjpeg -s WIDTH_THAT_YOU_WANT x HEIGHT_THAT_U_WANT -vframes 1 -ss TIME_FRAME_TO_CAPTURE -an FILENAME_OF_YOUR_IMAGE.jpg") ;
}
else{
 $thumb = (PATH_OF_YOUR_FFMPEG." …
veedeoo 474 Junior Poster Featured Poster

to get the dimension of the 0.jpg, just add this code

list($x,$y) = getimagesize('http://i2.ytimg.com/vi/'.$v_id.'/0.jpg');  
echo 'Image Widht: '.$x.'<br/>';
echo 'Image Height: '.$y.'<br/>';

You can then device some kind of if statement to sort out the dimension you want to use.

example of video with maxresdefault.jpg

  1. this is o.jpg http://i.ytimg.com/vi/9kD8sxIjVuc/0.jpg
  2. this is a blowup 0.jpg http://i.ytimg.com/vi/9kD8sxIjVuc/maxresdefault.jpg
  3. this is the hqdefault.jpg http://i.ytimg.com/vi/9kD8sxIjVuc/hqdefault.jpg

Notice the quality differences ?? Pretty much the hqdefault.jpg is the same as the o.jpg..

veedeoo 474 Junior Poster Featured Poster

the /0.jpg is the very large image they created after upload, and is more likely that if the video is of high quality or encoded in HD then the /0.jpg is also equivalent to either maxresdefault.jpg or hqdefault.jpg.

Having the maxresdefault and hqdefault included in this discussion, we cannot rely on its availability. The reason is that the encoder will not know the bitrate of the video uploaded by user, until it is being process. Based on the source bitrate, encoder will decide programmatically if it will be encoded as 1080p 740, or just a reqular quality video. I don't see any logical reason behind the 500kb bit rate video being encoded in the maxrate bitrate of 5000kb, that will not make the output any better. FFmpeg or any encoder cannot provide a higher quality beyond the quality of the input.

So in short, you are better of taking the /0.jpg instead of taking chances on the maxresdefault.jpg or hqdefault.jpg which may not be available.

veedeoo 474 Junior Poster Featured Poster

Here is a function that will do it for you automatically, just provide the url of the video and you have the choice which thumb you want to show.

<?php

## written and provided to you by veedeoo or poorboy 2012.

## public Notice to all it may concern.
## this script is excluded from any youtube API project I have association with, and is not included in the non-disclosure agreement signed by me for the year 2010 - 2012.
## this script is free to use any way you like it, as long as it does not violate youTube's terms of service as described and defined in http://www.youtube.com/static?gl=US&template=terms.
## if you are a developer, and this script is going to be use in part or in full within your applications using youtube API, then instructions and rules are written in https://developers.google.com/youtube/creating_monetizable_applications.


function getVideoId($url)
    {
    $url = $url.'&';
    $pattern = '/v=(.+?)&+/';
    preg_match($pattern, $url, $matches);
    return ($matches[1]);
    }

## just add the url of the video from youtube as shown in my example below.

$v_id = getVideoId('http://www.youtube.com/watch?v=wUjT5Yt6TbU');
echo "video ID: ".$v_id;
echo '<br/>Big Image:<br/><img src="http://i2.ytimg.com/vi/'.$v_id.'/0.jpg" /> <br/>';
echo 'Image Two:<br/><img src="http://i2.ytimg.com/vi/'.$v_id.'/default.jpg" /> <br/>';
echo 'Image Three:<br/><img src="http://i2.ytimg.com/vi/'.$v_id.'/1.jpg" /> <br/>';
echo 'Image Four:<br/><img src="http://i2.ytimg.com/vi/'.$v_id.'/2.jpg" /> <br/>';
echo 'Image Five:<br/><img src="http://i2.ytimg.com/vi/'.$v_id.'/3.jpg" /> <br/>';

?>
veedeoo 474 Junior Poster Featured Poster

Hi,

Do you mean first frame as image? or first frame up to some set time frame as video?

if you only need the thumbnail, then thats pretty easy I think.. here is a demo of my not-so-alpha-buggy-trash-bin NON-Zend dependent Youtube API .First public preview :).

Script is not available for public, because I am in agreement with my brother who is running this API project, but I think it is worth previewing it to the public as the development progresses.. besides, developer don't really have to rely on Zend ????? no! I still love Zend because I invested lots of money on the certification, I don't need for a profession in Mathematics and Physics. ... :)

veedeoo 474 Junior Poster Featured Poster

Hi,

for the editor notepad++ will do. It maybe not the best out there, but that's what I use all the time and it support programming languages from ADA to YML.. Learning C , before learning C++ would not hurt. In fact, it will give you a really good foundation in coding practices. Please read more here.

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.