curso de php para iniciantes

Upload: eugeniodicastro

Post on 08-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Curso de PHP Para Iniciantes

    1/23

    Basic PHP Syntax

    PHP is a server side scripting language used on the Internet to create dynamic webpages. It is often coupled with MySQL, a relational database server that can store theinformation and variables the PHP files may use. Together they can create everythingfrom the simplest web site to a full blown business web site, an interactive web forum,or even an online role playing game.

    Learn more about PHP.

    Before we can do the big fancy stuff we must first learn the basics from which we buildon.

    1. Start by creating a blank file using any program that can save inplain textformat.

    2. Save your file as a .PHP file , for example mypage.php. Saving a page with the.php extension tells your server that it will need to execute the PHP code.

    3.Enter the statement to let the browser know the PHP code is done.

    Every section of PHP code starts and ends by turning on and off PHP tags to let theserver know that it needs to execute the PHP in between them. Here is an example:

    Everything between the is read as PHP code. The

  • 8/6/2019 Curso de PHP Para Iniciantes

    2/23

    you can create a larger block of textand it will all be commented out*/

    ?>

    One reason you may want to put a comment in your code is to make a note to yourselfabout what the code is doing for reference when you edit it later. You may also want to

    put comments in your code if you plan on sharing it with others and want them tounderstand what it does, or to include your name and terms of use within the script.

    PRINT and ECHO Statements

    First we are going to learn about the echo statement, the most basic statement in PHP.What this does is output whatever you tell it to echo. For example:

    This would return the statementI like About. Notice when we echo a statement, it iscontained within quotation marks [].

    Another way to do this is to use the print function. An example of that would be:

    There is a lot of debate about which is better to use or if there is any difference at all.Apparently in very large programs that are simply outputting text the ECHO statementwill run slightly faster, but for the purposes of a beginner they are interchangeable.

    Another thing to keep in mind is that all of your print/echoing is contained between

    quotation marks. If you want to use a quotation mark inside of the code, you must use abackslash:

    When you are using more than one line of code inside your php tags, you must separateeach line with a semicolon [;]. Below is an example of printing multiple lines of PHP,right inside your HTML:PHP Test Page

  • 8/6/2019 Curso de PHP Para Iniciantes

    3/23

    As you can see, you can insert HTML right into your php print line. You can format theHTML in the rest of the document as you please, but remember to save it as a .php

    file.

    Variables

    The next basic thing you need to learn how to do is to set a variable. A variable issomething that represents another value.

    This sets our variable, $like, to our previousI like Aboutstatement. Notice again thequotation marks [] used, as well as the semicolon [;] to show the end of thestatement. The second variable $num is an integer, and therefore does not use thequotation marks. The next line prints out the variable $like and $num respectively. Youcan print more than one variable on a line using a period [.], for example:

    This shows two examples of printing more than one thing. The first print line prints the$like and $num variables, with the period [.] to separate them. The third print line printsthe $like variable, a blank space, and the $num variable, all separated with periods. Thefifth line also demonstrates how a variable can be used within the quotation marks [""].

    A few things to remember when working with variables: they are CaSe SeNsitiVe,they are always defined with a $, and they must start with a letter or an underscore (not

    a number.) Also note that if needed you can dynamically build variables. For a morethorough look at variables, see ourGuide to Variables.

    Arrays

    While a variable can hold a single piece of data, an array can hold a string of relateddata. Its use may not be apparent right away, but will become clearer as we start usingloops and MySQL. Below is an example:

  • 8/6/2019 Curso de PHP Para Iniciantes

    4/23

    The first array ($friend) is arranged using integers as the key (the key is the informationbetween the [brackets]) which is handy when using loops. The second array ($age)shows that you can also use a string (text) as the key. As demonstrated the values arecalled by print in the same way a regular variable would be.

    The same principals apply to arrays as variables: they are CaSe SeNsitiVe, they arealways defined with a $, and they must start with a letter or an underscore (not anumber.)

    Operands

    You have probably all heard the term expression used in mathematics. We useexpressions in PHP to preform operations and give an answer to a single value. These

    expressions are made up of two parts, the operators and the operands. The operands canbe variables, numbers, strings, boolean values, or other expressions. Here is an example:

    a = 3 + 4

    In this expression the operands are a, 3 and 4

    b = (3 + 4) / 2

    In this expression the expression (3+4) is used as an operand along with b and 2.

    Operators

    Now that you understand what an operand is we can go into more detail about whatoperators are. Operators tell us what to do with operands, and they fall into three majorcategories:

  • 8/6/2019 Curso de PHP Para Iniciantes

    5/23

    Mathematical:+(plus), - (minus), / (divided by), and * (multiplied by)

    Comparison:> (greater than), < (less than), == (equal to), and != (not equal to)

    Boolean:&& (true if both operands are true), || (true if at least one operand is true), xor (true ifONLY one operand is true), and ! (true if a single operand is false)

    Mathematical operators are exactly what they are called, they apply mathematicalfunctions to the operands. Comparison is also pretty straight forward, they compare oneoperand to another operand. Boolean however may need a little more explaining.

    Boolean is an extremely simple form of logic. In Boolean every statement is either Trueor False. Think of a light switch, it must either be turned on or off, there is no in

    between. Let me give you an example:

    $a = true;$b = true;$c = false;

    $a && $b;This is asking for $a and $b to both be true, since they are both true, this expression isTRUE

    $a || $b;This is asking for $a or $b to be true. Again this is a TRUE expression

    $a xor $b;This is asking for $a or $b, but not both, to be true. Since they are both true, thisexpression is FALSE

    ! $a;This is asking for $a to be false. Since $a is true, this expression is FALSE

    ! $c;This is asking for $c to be false. Since that is the case, this expression is TRUE

    Conditional Statements

    Conditionals allow your program to make choices. Following the same sort ofbooleanlogic you just learned about, the computer can only make two choices; true or false. Inthe case of PHP this is accomplished using IF : ELSE statements. Below is an exampleof an IF statement that would apply a senior's discount. If $over65 is false, everythingwithin the {brackets} is simply ignored.

  • 8/6/2019 Curso de PHP Para Iniciantes

    6/23

    {$price = .90;}

    print "Your price is $" . $price;?>

    However, sometimes just the IF statement isn't enough, you need the ELSE statement aswell. When using just the IF statement the code within the brackets either will (true) orwill not (false) be executed before carrying on with the rest of the program. When weadd in the ELSE statement, if the statement is true it will execute the first set of codeand if it is false it will execute the second (ELSE) set of code. Here is an example:

  • 8/6/2019 Curso de PHP Para Iniciantes

    7/23

    }}?>

    This program will first check if they are eligible for the senior's discount. If they are not,it will then check if they are eligible for a student discount, before returning the non-

    discounted price.

    WHILE Loops

    In PHP there are several different types of loops. Basically what a loop does is evaluatea statement as true or false. If it is true it executes some code and then alters the originalstatement and starts all over again by re-evaluating it. It continues to loop through thecode like this until the statement becomes false.

    Here is an example in its simplest form:

    Basically what this does is: while a number is greater than or equal to 10 it prints thenumber. The ++ adds one to the number, however this could also be phrased as $num =$num + 1; Once the number becomes greater than 10, in our case it becomes 11, then it

    stops executing the code within the {brackets}

    Below is an example of how you can combine a loop with a conditional

  • 8/6/2019 Curso de PHP Para Iniciantes

    8/23

    FOR Loops

    A FOR loop is very similar to a WHILE loop in that it continues to process a block ofcode until a statement becomes false, however everything is defined in a single line. The

    basic structure for a FOR loop is:

    for ( start; conditional; increment) { code to execute; }

    Let's go back to our first example using the WHILE loop, where we printed out thenumbers 1 through 10 and do the same thing using a FOR loop.

    The FOR loop can also be used in conjunction with a conditional, just like we did withthe WHILE loop:

    FOREACH Loops

    To understand FOREACH loops you have to remember what we learned about arrays.If you recall an array (unlike a variable) contains a group of data. When using a loopwith an array, instead of having a counter that goes until proven false the FOREACH

    loop continues until it has used all values in the array. So for example if an arraycontained 5 pieces of data, then the FOREACH loop would execute 5 times. More usesfor arrays and FOREACH loops will become apparent when you start importing datafrom MySQL.

    A FOREACH loop is phrased like this: FOREACH (array as value) { what to do; }

    Here is an example of a FOREACH loop:

  • 8/6/2019 Curso de PHP Para Iniciantes

    9/23

    Once you understand that concept you can then use the FOREACH loop to do morepractical things. Let's say an array contains the ages of 5 family members. Then we willmake a FOREACH loop that will determine how much it costs for each of them to eaton a buffet that has varied prices based on age. We will use the following pricingsystem: Under 5 is free, 5-12 years costs $4 and over 12 years is $6.

    PHP Functions

    Afunction is something that performs a specific task. People write functions if theyplan on doing the same task over and over again. This allows you to only write the codeonce and save a lot of time and space.

    Although in the next few pages we will lean how to write our own functions, PHP has

    several functions that already exist for us to use. Although they all have different uses,all functions are phrased as: name(argument). The name being the name of thefunction, and the argument being the value(s) it is using.

    Here are some examples of functions already in PHP:

  • 8/6/2019 Curso de PHP Para Iniciantes

    10/23

    $c = round(12.3);print "The absolute value of -.43 is " . $a . "
    ";print "The square root of 16 is " . $b . "
    ";print "12.3 rounded is " . $c . " and 12.5 rounded is " . round(12.5);?>

    This gives an example of three functions; absolute value, square root, and rounding. Asyou can see you can use the function right in the print statement or you can assign it to avariable. A list of functions canbe found here.

    Time and Date

    PHP has the ability to dynamically generate the time and date. Using a simple line ofcode we are able to include this on our site, however it is important to know how theformatting works.

    The above code outputs a long string of numbers. What these numbers represent is thetime based in the amount of seconds that have passed since January 1 1970 00:00:00GMT. This number can also be assigned to a variable:

    Although this is a handy feature, sometimes you want a more formatted and humanfriendly representation of the date. You can use the date function in conjunction withthe time function to display this in the format ofdate ( format , time ) In our case we

    want the start time to be now, so we will call the time first. We will demonstrate manydifferent types of formatting

    When you run this code you will see that the information is formatted in many differentways. What each of the letters means for formatting is explained on the next page.

    Date Function Formatting

  • 8/6/2019 Curso de PHP Para Iniciantes

    11/23

    As you can see in our last example there are tons of different formats that can be used inthe date feature. Below is a summary of the variable used in date, and what each does.Remember they ARE CaSe sEnsItIVe:

    DAYS

    d - day of the month 2 digits (01-31)

    j - day of the month (1-31)D - 3 letter day (Mon - Sun)l - full name of day (Monday - Sunday)

    N - 1=Monday, 2=Tuesday, etc (1-7)S - suffix for date (st, nd, rd)w - 0=Sunday, 1=Monday (0-6)z - day of the year (1=365)

    WEEKW - week of the year (1-52)

    MONTH

    F - Full name of month (January - December)m - 2 digit month number (01-12)n - month number (1-12)M - 3 letter month (Jan - Dec)t - Days in the month (28-31)

    YEARL - leap year (0 no, 1 yes)o - ISO-8601 year number (Ex. 1979, 2006)Y - four digit year (Ex. 1979, 2006)y - two digit year (Ex. 79, 06)

    TIMEa - am or pmA - AM or PMB - Swatch Internet time (000 - 999)g - 12 hour (1-12)G - 24 hour c (0-23)h - 2 digit 12 hour (01-12)H - 2 digit 24 hour (00-23)i - 2 digit minutes (00-59)s 0 2 digit seconds (00-59)

    OTHERe - timezone (Ex: GMT, CST)I - daylight savings (1=yes, 0=no)O - offset GMT (Ex: 0200)Z - offset in seconds (-43200 - 43200)r - full RFC 2822 formatted date

    Writing Functions

  • 8/6/2019 Curso de PHP Para Iniciantes

    12/23

    While having pre-made functions is useful, for most things you are going to want theflexibility to write your own custom functions. A function you create takes this shape:function functionname () { your code }

    Below is an example of two simple functions:

  • 8/6/2019 Curso de PHP Para Iniciantes

    13/23

    {mul();$start++;}

    print "";?>

    One new thing you may have noticed is "GLOBAL". Since the variable $start is notdefined within the function, we use the tag "GLOBAL" to let it know that it needs to usethe $start variable that we have defined outside of the function.

    Connect toMySQL

    Interacting with MySQL makes PHP a far more powerful tool. In this tutorial we willgo through some of the most common ways PHP interacts with MySQL. To followalong with what we are doing, you will need to create a database table by executing thiscommand:

    CREATE TABLE friends (name VARCHAR(30), fav_color VARCHAR(30), fav_foodVARCHAR(30), pet VARCHAR(30));INSERT INTO friends VALUES ( "Rose", "Pink", "Tacos", "Cat" ), ( "Bradley","Blue", "Potatoes", "Frog" ), ( "Marie", "Black", "Popcorn", "Dog" ), ( "Ann","Orange", "Soup", "Cat" )

    This will create a table for us to work with, that has friends' names, favorite colors,favorite foods, and pets.

    The first thing we need to do in our PHP file is connect to the database. We do thatusing this code:

    Of course you will replace server, username, password, and Database_Name with theinformation relevant to your site. If you are unsure what these values are, contact yourhosting provider.

    Retrieve DataNext we will retrieve the information from the database table we created called"friends"// Collects data from "friends" table$data = mysql_query("SELECT * FROM friends")or die(mysql_error());

    And we will then temporally put this information into an array to use:

  • 8/6/2019 Curso de PHP Para Iniciantes

    14/23

    // puts the "friends" info into the $info array$info = mysql_fetch_array( $data );

    Now let's print out the data to see if it worked:

    // Print out the contents of the entry

    Print "Name: ".$info['name'] . " ";Print "Pet: ".$info['pet'] . "
    ";

    However this will only give us the first entry in our database. In order to retrieve all theinformation, we need to make this a loop. Here is an example:

    while($info = mysql_fetch_array( $data )){Print "Name: ".$info['name'] . " ";Print "Pet: ".$info['pet'] . "
    ";}

    So let's put all the these ideas together to create a nicely formatted table with this finalphp code:

    SQL Queries with PHP

    Now that you have done one query, you can do more complicated queries using the

    same basic syntax. If you have forgotten the queries, you can review them in theMySQL glossary.

    Let's try to do a query of our database for people who have cats for a pet. We will dothis by adding a WHERE clause to set pet equal to Cat.

  • 8/6/2019 Curso de PHP Para Iniciantes

    15/23

    die(mysql_error());mysql_select_db("Database_Name") or die(mysql_error());$data = mysql_query("SELECT * FROM friends WHERE pet='Cat'")or die(mysql_error());Print "";while($info = mysql_fetch_array( $data ))

    {Print "";Print "Name: ".$info['name'] . " ";Print "Color: ".$info['fav_color'] . " ";Print "Food: ".$info['fav_food'] . " ";Print "Pet: ".$info['pet'] . " ";}Print "";?>

    Create Tables

    Following this same structure, we can connect to a database and create new tables. Atthe end we will print a line, so we know that it is done executing:

    I find this method is often used when installing a PHP program someone else haswritten. Often an install file includes a way for the user to update the MySQL databasefrom the browser. This allows people less familiar with the code to install the programmore easily.

    Insert Into Tables

    We can use the same method of using SQL commands to populate our database as wedid to create it. Here is an example:

  • 8/6/2019 Curso de PHP Para Iniciantes

    16/23

    Creating a Form

    Sometimes it is useful to collect data from your website users and store this informationin a MySQL database. We have already seen you can populate a database using PHP,now we will add the practicality of allowing the data to be added through a user friendlyweb form.

    The first thing we will do is create a page with a form. For our demonstration we willmake a very simple one:

    Your Name:
    E-mail:
    Location:

    Insert Into - Adding Data from a Form

    Next you need to make process.php, the page that our form sends its data to. Here is anexample of how to collect this data to post to the MySQL database:

  • 8/6/2019 Curso de PHP Para Iniciantes

    17/23

    The first thing you should notice is a field called idthat is set to

    AUTO_INCREMENT. What this data type means is that it will count up to assigneach file a unique file ID starting at 1 and going to 9999 (since we specified 4 digits).You will also probably notice that our data field is called LONGBLOB. There aremany types of BLOB as we have mentioned before. TINYBLOB, BLOB,MEDIUMBLOB, and LONGBLOB are your options, but we set ours to LONGBLOB

    to allow for the largest possible files.

    Next, we will create a form to allow the user to upload her file. This is just a simpleform, obviously you could dress it up if you wanted:

    Description:

    File to upload:

    Be sure to take notice of the enctype, it is very important!

    Adding File Uploads toMySQL

    Next we need to actually create upload.php, which will take our users file and store it inour database. Below is sample coding for upload.php.

  • 8/6/2019 Curso de PHP Para Iniciantes

    18/23

    Next it uses theADDSLASHES function. What this does is add back slashes if neededinto the file name so that we won't get an error when we query the database. Forexample if we have Billy'sFile.gif, it will convert this to Billy\'sFile.gif. FOPEN opensthe file and FREAD is a binary safe file read, so that the ADDSLASHES is applied todata within the file if needed.

    Next we add all of the information our form collected into our database. You will noticewe listed the fields first, and the values second so we don't accidently try to insert datainto our first field (the auto assigning ID field.)

    Finally we print out the data for the user to review.

    Retrieving Files

    We already learned how to retrieve plain data from our MySQL database. Likewise,storing your files in a MySQL database wouldn't be very practical if there wasn't a wayto retrieve them. The way we are going to learn to do this is by assigning each file a

    URL based on their ID number. If you will recall when we uploaded the files weautomatically assigned each of the files an ID number. We will use that here when wecall the files back. Save this code as download.php

    Now to retrieve our file, we point our browser to:http://www.yoursite.com/download.php?id=2 (replace the 2 with whatever file ID youwant to download/display)

    This code is the base for doing a lot of things. With this as a base you can add in adatabase query that would list files, and put them in a drop down menu for people tochoose. Or you could set ID to be a randomly created number so that a different graphicfrom your database is randomly displayed each time a person visits. The possibilitiesare endless.

    Removing Files

    Here is a very simple way of removing files from the database. You want to be carefulwith this one!! Save this code as remove.php

  • 8/6/2019 Curso de PHP Para Iniciantes

    19/23

    $delete = MYSQL_QUERY($query);print "File ID $id has been removed from the database";?>

    Like our previous code that downloaded files, this script allows files to be removed justby typing in their URL: http://yoursite.com/remove.php?id=2 (replace 2 with the ID you

    want to remove.) For obvious reasons, you want to be careful with this code. This is ofcourse for demonstration, when we actually build applications we will want to put insafeguards that ask the user if they are sure they want to delete, or perhaps only allow

    people with a password to remove files. This simple code is the base we will build on todo all of those things.

    Create a Database

    On our site, we have tutorials about adding data to a MySQL database, and tutorialsabout uploading files, but recently one ofour forum users asked:"I know how to submit data into a mySQL table through a form. Now I want to upload

    the image file to the remote directory (say, 'images/') but at the same time save the file-name in the table. "This is a very common question because it has a lot of uses. Often you want a user to beable to upload a photo, but you don't want to bog down your database space by savingall the images directly into the database. You instead save the image to your server, butkeep a record in the database of what file was saved so you can easily reference theimage when needed. First let's create a database:CREATE TABLE employees (name VARCHAR(30), email VARCHAR(30), phoneVARCHAR(30), photo VARCHAR(30))This SQL code creates a database called 'employees' that can hold their name, email,

    phone and the name of their photo.

    Creating a Form

    Name:
    E-mail:
    Phone:
    Photo:

    This is simply an HTML form that you would use to collect information to be added to

    the database. We could add more fields if we wanted, but then we would also need toadd the appropriate fields to our MySQL database.

    Processing the Data

  • 8/6/2019 Curso de PHP Para Iniciantes

    20/23

    //This is the directory where images will be saved$target = "images/";$target = $target . basename( $_FILES['photo']['name']);

    //This gets all the other information from the form$name=$_POST['name'];

    $email=$_POST['email'];$phone=$_POST['phone'];$pic=($_FILES['photo']['name']);

    // Connects to your Databasemysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());mysql_select_db("Database_Name") or die(mysql_error()) ;

    //Writes the information to the databasemysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone','$pic')") ;

    //Writes the photo to the serverif(move_uploaded_file($_FILES['photo']['tmp_name'], $target)){

    //Tells you if its all okecho "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, andyour information has been added to the directory";}else {

    //Gives and error if its notecho "Sorry, there was a problem uploading your file.";}?>

    This code should be saved as add.php. To understand what each step of this script isdoing it is best to read the comments within the code. Basically it gathers theinformation from the form and then writes it to the MySQL database. Once that is done,it saves the file to the /images directory (relative to the script) on your server.

    If you are only allowing photo uploads, you might considerlimiting the allowed filetypes to jpg, gif and png. We also don't check if the file already exists, so if two people

    both upload a file called MyPic.gif, one will overwrite the other. A simple way to

    remedy this would be to simply rename each file with a unique ID.

    Viewing Your Data

  • 8/6/2019 Curso de PHP Para Iniciantes

    21/23

    mysql_select_db("Database_Name") or die(mysql_error()) ;

    //Retrieves data from MySQL$data = mysql_query("SELECT * FROM employees") or die(mysql_error());

    //Puts it into an array

    while($info = mysql_fetch_array( $data )){

    //Outputs the image and other dataEcho "
    ";Echo "Name: ".$info['name'] . "
    ";Echo "Email: ".$info['email'] . "
    ";Echo "Phone: ".$info['phone'] . " ";}?>

    This script very simply queries the database and retrieves all of the information in it. It

    then echos each back until it has shown all the data.

    To show the image, we just use normal HTML for the image, and only change the lastpart (the actual image name) with the image name stored in our database. For moreinformation on retrieving information from the database, read this tutorial.

    The HTML Form

    This script will allow you to upload files from your browser to your hosting, using PHP.The first thing we need to do is create an HTML form that allows people to choose thefile they want to upload.

    Please choose a file:
    This form sends data to the file "upload.php", which is what we will be creating next toactually upload the file.

    Uploading the File

    The actual file upload is very simple:

  • 8/6/2019 Curso de PHP Para Iniciantes

    22/23

    }?>This very small piece of code will upload files sent to it by your HTML form.

    1. The first line $target = "upload/"; is where we assign the folder that files will beuploaded to. As you can see in the second line, this folder is relative to the

    upload.php file. So for example, if your file was atwww.yours.com/files/upload.php then it would upload files towww.yours.com/files/upload/yourfile.gif. Be sure you remember to create thisfolder!

    2. We are not using $ok=1; at the moment but we will later in the tutorial.3. We then move the uploaded file to where it belongs using move_uploaded_file

    (). This places it in the directory we specified at the beginning of our script. Ifthis fails the user is given an error message, otherwise they are told that the filehas been uploaded.

    4.Limit the File Size5. if ($uploaded_size > 350000)

    {echo "Your file is too large.
    ";$ok=0;}

    6. Assuming that you didn't change the form field in our HTML form (so it is stillnamed uploaded), this will check to see the size of the file. If the file is largerthan 350k, they are given a file too large error, and we set $ok to equal 0.

    7. You can change this line to be a larger or smaller size if you wish by changing350000 to a different number. Or if you don't care about file size, just leavethese lines out.

    8.Limit Files by Type9. if ($uploaded_type =="text/php")

    {echo "No PHP files
    ";$ok=0;}

    10.The code above checks to be sure the user is not uploading a PHP file to yoursite. If they do upload a PHP file, they are given an error, and $ok is set to 0.

    11.if (!($uploaded_type=="image/gif")) {echo "You may only upload GIF files.
    ";$ok=0;}

    12.In our second example we only allow users to upload .gif files, and all other

    types are given an error before setting $ok to 0. You can use these basicexamples to allow or deny any specific file types.

    13. Putting It Together14.

  • 8/6/2019 Curso de PHP Para Iniciantes

    23/23

    if ($uploaded_size > 350000){echo "Your file is too large.
    ";$ok=0;}

    //This is our limit file type conditionif ($uploaded_type =="text/php"){echo "No PHP files
    ";$ok=0;}

    //Here we check that $ok was not set to 0 by an errorif ($ok==0){Echo "Sorry your file was not uploaded";}

    //If everything is ok we try to upload itelse{if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){echo "The file ". basename( $_FILES['uploadedfile']['name']). " has beenuploaded";}else{echo "Sorry, there was a problem uploading your file.";}}?>

    15. Final Thoughts16.Obviously if you are allowing file uploads you are leaving yourself open to

    people uploading lots of undesirable things. One precaution is not allowing themto upload any php, html, cgi, etc. files that could contain malicious code. This

    provides more safety but is not sure fire protection.17.Another idea is to make the upload folder private, so that only you can see it.

    Then once you have seen what has been uploaded, you can approve (move) it or

    remove it. Depending on how many files you plan on receiving this could betime consuming and impractical.

    18.In short, this script is probably best kept in a private folder. We don'trecommend putting it somewhere where the public can use it, or you may end upwith a server full of useless or potentially dangerous files. If you really want thegeneral public to be able to utilize your server space, we suggest writing in asmuch security as possible.