Comedy Hometown - Watch Comedy Hometown's Latest Video!

Welcome to Havenworld's Gaming, Computing and Programming Forums!

Unlock extra board access and remove this notice by registering for free below:
Choose username: Email:
Choose password: Antibot:
Type the letters shown in the picture to the left:
Verify password:

Pages: [1] 2 3 ... 10
 1 
 on: Today at 10:34:50 am 
Last post by Matt - Started by MarisaVipponah
Read times
Matt

Joined: Jan 1970

Reputation: 0
Posts:
Oh right, never knew that - thanks a lot for taking the time to write this :)

 2 
 on: Today at 08:43:54 am 
Last post by MarisaVipponah - Started by MarisaVipponah
Read times
MarisaVipponah

Joined: Jan 1970

Reputation: 0
Posts:
Major accounts which are also called as single accounts are typically singled out for special attention. Important customers who have multiple divisions in many locations are offered major account contracts, which provide uniform pricing and coordinated services for all customer divisions. Large accounts are often handled by a strategic management account team with cross-functional personnel who handle all aspects of the relationship.

Major account management is growing. A buyer concentration increases through mergers and acquisitions. Fewer buyers account for a larger share of a company’s sales. Many buyers are centralizing their purchase for certain items, which gives them more bargaining power. Sellers in turn need to devote more attention to these major buyers. Still another factor is that, as products become more complex, more groups in the buyer’s organization become involved in the purchase process. The typical salesperson might not have the skill, authority or coverage to be effective in selling to the large buyer.

In selecting major accounts, companies look for accounts that purchase a high volume, purchase centrally, require a high level of service in several geographic locations, which may be price sensitive and may want a long term partnering relationship. Major accounts manager have lots of duties such as acting as the single point of contact, developing and growing customer business, understanding customer decision process, identifying value added opportunities, providing competitive intelligence, negotiating sales and channeling customer service. Major accounts manages is typically evaluated on their effectiveness in growing their share of accounts business and on their achievement of annual profit and sales volume goals. There is always a risk that competitors match or beat a price that we have fixed or increased cost may lead to rise in price. So models, whether it is media based model or photo  models for hire :rose-dead:, the choice should be based on the cost involved in hiring them and the cost benefit analysis of our business.

 3 
 on: September 04, 2010, 06:24:06 am 
Last post by Project Evolution - Started by Project Evolution
Read times
Project Evolution

Joined: Jan 1970

Reputation: 0
Posts:
Thats to Malik who requested this tutorial on my Request a Tutorial thread. I was thinking of calling this Simple-UP or SUP just for fun. If people decide to pursue a project or post tutorials with it, I guess this is the name you can use? :p
 
In this tutorial you will learn common uses of PHP and SQL. Today you will learn how to create a file-sharing website, by the end of this tutorial you will know how to write an upload script in PHP along with storing data in an SQL database.
 
This tutorial assumes you already know the basics of web design and how to use PHP along with limited knowledge of SQL. Let us begin.
 
Getting Started

Let us begin with the index.php file. Here is what we are going to be using,
Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Anthony's File Sharing Site - Index</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
        <div class="content">
            <div id="header">
                <img src="http://www.google.org/images/FileSharingLogo.png" alt="Logo" />
            </div>
            <div id="leftcontent">
            </div>
            <div id="rightcontent">
            </div>
        </div>
        <?php
        ?>

    </body>
</html>
This should be obvious enough to void an explanation. The only thing worth mentioning is we are defining an XHTML Strict document using the !DOCTYPE tag.
 
Next off we will need another PHP file, we wil call it upload.php,
Code: [Select]
<?php
/* 
 * This file contains functions for the physical uploading of files
 */
 
?>

 
And while your at it lets start with a CSS stylesheet to define the basics of a simple template I made, and then create a new directory called images.
Code: [Select]
/*
   Document   : style.css
   Created on : 31-Aug-2010, 1:59:50 PM
   Author     : Anthony`
   Description:
       Purpose of the stylesheet follows.
*/
body {
   background-color: rgb(220, 220, 220);
   margin: auto; /* Centers content */
   font: 15px arial, sans-serif; /* Sets the font */
}
/*
   This is set as a class incase seperate content is used
*/
.content {
   margin: auto; /* Centers content */
   width: 80%; /* Sets width of main container */
   border: gray 1px solid;
   margin-top: 10px; /* move the header down slightly */
   padding: 5px;
}
#header {
   border-bottom: gray 1px solid; /* Sets all border properties */
   padding: 5px;
}
#leftcontent {
   width: 25%; /* define the width of the content */
   float: left; /* sets all content to the left */
   padding: 5px;
   margin-right: 5px;
}
#rightcontent {
   overflow: auto;
   padding: 5px;
   margin-left: 25px;
   border-left: gray 1px solid;
}
#rightcontent p.title {
   font-weight: bold;
   text-decoration: underline;
   font-size: 18px;
   text-align: center;
}

This is a basic template for you to use for this tutorial. I have included the logo at the bottom of this post, otherwise you can upload your image to the images directory and edit the img tag as such.
 
Writing the upload script

Before we get to writing the index page, we should begin with the upload script. PHP has a very easy way of controlling how to upload files to the webserver, and all this access comes from the $_FILES super global array. The $_FILES array comes with a number of ways to handle different aspects of the file, here is a simple list of these different functions,
Quote
$_FILES["file"]["name"] - the name of the uploaded file
$_FILES["file"]["type"] - the type of the uploaded file
$_FILES["file"]["size"] - the size in bytes of the uploaded file
$_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server
$_FILES["file"]["error"] - the error code resulting from the file upload
As you can see, there is an index named file in the array, you will learn why that is there later on.
 
So what are we waiting for? Lets begin scripting that upload page!
 
We are going to be going in the index.php file and adding a simple form submission box so we can input our files to be uploaded. Its as simple as including a couple tags,
Code: [Select]
                <p class="title">Upload your file</p>
                <form name="input" action="upload.php" method="post" enctype="multipart/form-data">
                    Select File: <input type="file" name="file" />
                    <input type="submit" value="Submit" />
                </form>
In the div containing the id rightcontent. This is now what the page should look like,
Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Anthony's File Sharing Site - Index</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
        <div class="content">
            <div id="header">
                <img src="http://www.google.org/images/FileSharingLogo.png" alt="Logo" />
            </div>
            <div id="leftcontent">
                <p>sdasas</p>
            </div>
            <div id="rightcontent">
                <p class="title">Upload your file</p>
                <form action="upload.php" method="post" enctype="multipart/form-data">
                    Select File: <input type="file" name="file" />
                    <input type="submit" value="Submit" />
                </form>
            </div>
        </div>
        <?php
        ?>

    </body>
</html>


If your unsure about the form tag, I will briefly go over this snippet.
  • The action attribute handles which script the form will submit the data to. In this case we set the attribute to the upload script named upload.php. When the form is submitted, data will be sent to that script from the file input users will input themselves.
  • The enctype attribute of the form tag specifies which content-type to use when submitting the form. This was a quote from W3Schools, in a nutshell this basically specifies how to transmit the data the upload script is going to receive, in this case, we are using multipart/form-data. This is to specify the form requires binary data.
  • We use the post function so we can transmit data without being visible to others, and this method supports no boundaries on how much data we can send.
So now we have our simple template and a simple form. What the heck use is that? Lets begin writing the upload.php script.
 
Remember that $_FILES function which were discussed earlier? This is where it comes into play. We will be utilizing this function in the following snippets of code. To start off, lets start writing the basic script first.
Code: [Select]
<?php
/* 
 * This file contains functions for the physical uploading of files
 */
 
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Anthony\'s File Sharing Site - Upload</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
        <div class="content">'
;
 if (
$_FILES['file']['error'] != 0) {
     echo 
'<p>Error uploading file: ' $_FILES['file']['error'] . '</p>';
 } else {
     echo 
'Upload: ' $_FILES['file']['name'] . '<br />';
     echo 
'Type: ' $_FILES['file']['type'] . '<br />';
     echo 
'Size: ' . ($_FILES['file']['size'] / 1024) . 'KB<br />';
     echo 
'Stored in: ' $_FILES['file']['tmp_name'];
 }
 echo 
'</div>
     </body>
     </html>'
;
?>


This may look confusing, but with a couple explanations you will understand how this all works.
  • Instead of specifying raw HTML tags on the page, we format our page using PHP echo. The reason I do this is to sort of provide a cleaner look at the page, instead of just focusing on the HTML and having to include PHP tags all the time, we can make this easier by echoing them. However its a better idea to do raw HTML when there is barely any PHP used in the page.
  • We utilize the $_FILES function. As you can see above, we are using the $_FILES function specifying two-dimensions. Both file and error in this case. file corresponds to the form we made back in index.php when we specified the name attribute. Take a look,
Code: [Select]
Select File: <input type="file" name="file" />
    As shown here, we made
name called: file. This must always be the first dimension of the $_FILES function if you plan on utilizing that file alone. error is used to indicate an error with the uploading process. If the value of $_FILES['file']['error'] is not 0, we throw an error message.
  • We then show the statistics of the file we uploaded. Take a look at the snippet, most of this is pretty obvious stuff. However, $_FILES['file']['tmp_name'] is the temporary name of the file PHP stores the original file as. Its stored in PHP's temp folder (if I recall correctly).
Okay, so now we have a little script here to make sure everything works as planned. If it works correctly, when you submit the file of your choice you should be redirected to upload.php and statistics should show in a box at the top of your page, if all is well, good job so far.
 
Next we want to actually store the file on the web server, in the above example we arent storing the actual file on the web server. To make this happen, we will be making some changes to the script, and using some new functions to help us take care of the job.
Code: [Select]
<?php
/* 
 * This file contains functions for the physical uploading of files
*/
// Must end with a '/'
$upload_dir 'upload/';
echo 
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Anthony\'s File Sharing Site - Upload</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
        <div class="content">
            <p class="title">File Statistics</p>'
;
if (
$_FILES['file']['error'] != 0) {
    echo 
'<p>Error uploading file: ' $_FILES['file']['error'] . '</p>';
} else {
    echo 
'Upload: ' $_FILES['file']['name'] . '<br />';
    echo 
'Type: ' $_FILES['file']['type'] . '<br />';
    echo 
'Size: ' . ($_FILES['file']['size'] / 1024) . 'KB<br /><br />';
    if (
file_exists($upload_dir $_FILES['file']['name'])) {
        echo 
'<b>File already exists!</b>';
    } else {
        
move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir $_FILES['file']['name']);
        echo 
'<b>Uploaded file: <i>' $_FILES['file']['name'] . '</i> to: ' $upload_dir '</b>';
    }
}
echo 
'</div>
     </body>
     </html>'
;
 

?>
  • You set the directory to where the content is held. At the top of the script there is a variable called $upload_dir which sets the location to where all files will be kept when uploaded. Make sure you always add the backslash to the end of the path!
  • We now physically upload the file to a certain directory on the web server. Here is the good part. We use an if statement to check if the file we uploaded is already in the directory you chose to keep all the content. If there is already the same file located, the script terminates and displays a message. However, if there isnt, the script moves the uploaded file from PHP's temporary location to the web server. The work is all done in the move_uploaded_file() function. It grabs that temporary file, and moves it to the directory you chose.
This is good and all, but what if we want to set restrictions such as maximum file size and/or type of file? Next off, we are going to set a size restriction and filter out files you do not want to specify. Here is the updated script,
Code: [Select]
<?php
/* 
 * This file contains functions for the physical uploading of files
*/
// Must end with a '/'
$upload_dir 'upload/';
$MAX_FILE_SIZE 1000000;
echo 
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Anthony\'s File Sharing Site - Upload</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
        <div class="content">
            <p class="title">File Statistics</p>'
;
if (
$_FILES['file']['error'] != 0) {
    echo 
'<p>Error uploading file: ' $_FILES['file']['error'] . '</p>';
} else {
    if (
$_FILES['file']['size'] < $MAX_FILE_SIZE &&
           
$_FILES['file']['type'] != "application/octet-stream") {
        echo 
'Upload: ' $_FILES['file']['name'] . '<br />';
        echo 
'Type: ' $_FILES['file']['type'] . '<br />';
        echo 
'Size: ' . ($_FILES['file']['size'] / 1024) . 'KB<br /><br />';
        if (
file_exists($upload_dir $_FILES['file']['name'])) {
            echo 
'<b>File already exists!</b>';
        } else {
            
move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir $_FILES['file']['name']);
            echo 
'<b>Uploaded file: <i>' $_FILES['file']['name'] . '</i> to: ' $upload_dir '</b>';
        }
    } else {
        echo 
'<b>The file is either too large or has a filetype not allowed to be uploaded!</b>';
    }
}
echo 
'</div>
     </body>
     </html>'
;
?>


And here is a slightly updated index.php,
Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Anthony's File Sharing Site - Index</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
        <div class="content">
            <div id="header">
                <img src="http://www.google.org/images/FileSharingLogo.png" alt="Logo" />
            </div>
            <div id="leftcontent">
                <p>sdasas</p>
            </div>
            <div id="rightcontent">
                <p class="title">Upload your file</p>
                <p>The maximum file size is ~1 MB, file types: application/octet-stream (such as
                .exe, .o, .psd, .arc, .bin, etc) are not allowed.</p>
                <form action="upload.php" method="post" enctype="multipart/form-data">
                    Select File: <input type="file" name="file" />
                    <input type="submit" value="Submit" />
                </form>
            </div>
        </div>
        <?php
        ?>

    </body>
</html>


Now its time to explain what we did in upload.php.
  • We created the $MAX_FILE_SIZE constant. This constant is used to set the limit to the maximum size (in bytes) of an uploaded file. If its too large, it does not upload and the script terminates.
  • We used an if statement to disallow certain MIME types. We used the if statement to filter out all files that have the MIME-type of application/octet-stream. Here is a list of all filetypes assosciated with different MIME-types, Webmaster Toolkit :: listing of mime types
You can use these settings to disallow other types. This is called black-listing because instead of specifying wich file types are allowed, we instead specify which files to disallow so we dont have such a huge if statement.
 
Storing our Information

Finally its time to get into some SQL. Storing information in a database is extremely useful, especially if your going to be storing lots of information for lots of data. Hence why SQL is included.
 
In this tutorial, I am going to be creating a configuration script which will just be used to hold fields that are used to login to the MySQL database. Here is the content of the script,
 
Code: [Select]
<?php
/* 
 * This small configuration script will be used to login to the
 * MySQL database.
 */
 
$mysql_server '';
 
$mysql_username '';
 
$mysql_password '';
 
$mysql_db '';
?>

Call it config.php, fill those variables in, and your good to continue on.
 
Now, we will do some slight editting to both our index.php and upload.php files so we can connect to the database. Not only will we be connecting to the database, we also will connect and query. Here is how we are going to accomplish the connection, index.php (nothing except a connection so far),
Code: [Select]
<?php
    
require_once('config.php');
    
$conn mysql_connect($mysql_server$mysql_username$mysql_password);
    if (!
$conn) {
        die(
'Unable to connect to database!');
    }
    
$db mysql_select_db($mysql_db$conn);
    if (!
$db) {
        die(
'Unable to select database!');
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Anthony's File Sharing Site - Index</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
        <div class="content">
            <div id="header">
                <img src="http://www.google.org/images/FileSharingLogo.png" alt="Logo" />
            </div>
            <div id="leftcontent">
                <?php
                ?>

            </div>
            <div id="rightcontent">
                <p class="title">Upload your file</p>
                <p>The maximum file size is ~1 MB, file types: application/octet-stream (such as
                .exe, .o, .psd, .arc, .bin, etc) are not allowed.</p>
                <form action="upload.php" method="post" enctype="multipart/form-data">
                    Select File: <input type="file" name="file" />
                    <input type="submit" value="Submit" />
                </form>
            </div>
        </div>
        <?php
            mysql_close
($conn);
        
?>

    </body>
</html>

upload.php,
Code: [Select]
<?php
/* 
 * This file contains functions for the physical uploading of files
*/
require_once('config.php');
// Must end with a '/'
$upload_dir 'upload/';
$MAX_FILE_SIZE 1000000;
echo 
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Anthony\'s File Sharing Site - Upload</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
        <div class="content">
            <p class="title">File Statistics</p>'
;
$conn mysql_connect($mysql_server$mysql_username$mysql_password);
if (!
$conn) {
    die(
'Unable to connect to database!');
}
$db mysql_select_db($mysql_db$conn);
if (!
$db) {
    die(
'Unable to select database!');
}
if (
$_FILES['file']['error'] != 0) {
    echo 
'<p>Error uploading file: ' $_FILES['file']['error'] . '</p>';
} else {
    if (
$_FILES['file']['size'] < $MAX_FILE_SIZE &&
           
$_FILES['file']['type'] != "application/octet-stream") {
        echo 
'Upload: ' $_FILES['file']['name'] . '<br />';
        echo 
'Type: ' $_FILES['file']['type'] . '<br />';
        echo 
'Size: ' . ($_FILES['file']['size'] / 1024) . 'KB<br /><br />';
        if (
file_exists($upload_dir $_FILES['file']['name'])) {
            echo 
'<b>File already exists!</b>';
        } else {
            
move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir $_FILES['file']['name']);
            
$query "INSERT INTO repository (FileName, Description, FileSize, FileType, Url, ImageUrl1)
                VALUES('" 
$_FILES[file][name] . "', 'test', " $_FILES[file][size] . ", " $_FILES[file][type] . ", '$upload_dir', 'lol')";
            
mysql_query($query$conn);
            echo 
'<b>Uploaded file: <i>' $_FILES['file']['name'] . '</i> to: ' $upload_dir '</b>';
        }
    } else {
        echo 
'<b>The file is either too large or has a filetype not allowed to be uploaded!</b>';
    }
}
echo 
'</div>
     </body>
     </html>'
;
mysql_close($conn);
?>


And I have included a new file called query.sql which will be used for you to query your database before continuing on.
Code: [Select]
CREATE TABLE repository
(
    ID_FILE int NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(ID_FILE),
    FileName char(35),
    Description char(50),
    FileSize char(10),
    FileType char(20),
    Url tinytext,
    ImageUrl1 tinytext
)


Make sure you query the database using the above SQL statements before continuing! THis is going to be a lot so put your thinking caps on. Index.php:
  • We opened a connection to the MySQL server before anything else. This is to insure we always initiate a connection before the page loads. As you can see, we load our login credentials and database info in the config.php file using the include_once() function.
  • Some text was added. We added text above the form to notify users of file restrictions. Nifty aint it.
Upload.php:
  • We initiated a connection to the MySQL server. After doing so, we then proceeded to choose a database name which is specified in the configuration file. After doing so, we make sure all this data is correct. We use the die() function if that is not the case so we dont happen to lose data that should be in the database. Why go to such extreme measures? Well think of it like this: if the script couldnt select the database, how would the information about the uploaded file get stored in the database? It wouldnt which would become a problem.
  • We execute a query on the database inserting data regarding information about the file. So far we are only filling in default values for show, I have provided a framework for you to work with and what I have provided is simply an example of how you can implement more functionality. The only data being automatically inserted is the file name, file size, file type and the path to where it is located.
Now that you have something to work with in index.php, hopefully you can figure out how to do some nifty tricks with it and edit the page to your liking.
 
Now its time we do some updating with the upload.php file so we can give the users a download link. Replace,
Code: [Select]
        if (file_exists($upload_dir . $_FILES['file']['name'])) {
            echo '<b>File already exists!</b>';
        } else {
            move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir . $_FILES['file']['name']);
            $query = "INSERT INTO repository (FileName, Description, FileSize, FileType, Url, ImageUrl1)
                VALUES('" . $_FILES[file][name] . "', 'test', " . $_FILES[file][size] . ", " . $_FILES[file][type] . ", '$upload_dir', 'lol')";
            mysql_query($query, $conn);
            echo '<b>Uploaded file: <i>' . $_FILES['file']['name'] . '</i> to: ' . $upload_dir . '</b>';
        }
With,
Code: [Select]
        if (file_exists($upload_dir . $_FILES['file']['name'])) {
            echo '<b>File already exists!</b>';
        } else {
            move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir . $_FILES['file']['name']);
            $query = "INSERT INTO repository (FileName, Description, FileSize, FileType, Url, ImageUrl1)
                VALUES('" . $_FILES[file][name] . "', 'test', " . $_FILES[file][size] . ", " . $_FILES[file][type] . ", '$upload_dir', 'lol')";
            mysql_query($query, $conn);
            $query = "SELECT COUNT(ID_FILE) as num FROM repository";
            $result = mysql_fetch_array(mysql_query($query, $conn));
            $file_id = $result['num'];
            echo '<b>Uploaded file: <i>' . $_FILES['file']['name'] . '</i> to: ' . $upload_dir . '</b><br />';
            echo 'Your file link is:
                <a href="http://'.$_SERVER['HTTP_HOST'].'/download.php?file_id='.$file_id.'">http://'.$_SERVER['HTTP_HOST'].'/download.php?file_id='.$file_id.'</a>';
 

        }
  • Another query is executed, this time using the SQL COUNT() function to determine the length of id of the next file. Basically, we use the count() function to get the next file id so every file has a unique file id.
  • We then display the link of the current file's download URL. We will create the download.php page soon, so hang tight! We use $_SERVER['HTTP_HOST'] to get the domain, thus having no need for a user to manually specify the domain.
Downloading our files

 
 
And finally, the last part of the tutorial! We will create a very simple download script because im very tired and am ready to sleep! Create a new file called download.php. Replace the content of whats inside your empty file with this,
Code: [Select]
<?php
require_once('config.php');
$conn mysql_connect($mysql_server$mysql_username$mysql_password);
if (!
$conn) {
    die(
'Unable to connect to database!');
}
$db mysql_select_db($mysql_db$conn);
if (!
$db) {
    die(
'Unable to select database!');
}
$file_id = (int) $_GET['file_id'];
$query "SELECT * FROM repository WHERE ID_FILE = '$file_id'";
$result mysql_query($query);
echo 
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Anthony\'s File Sharing Site - Download</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
        <div class="content">'
;
while (
$row mysql_fetch_assoc($result)) {
  echo 
'<p class="title">Now Downloading - ' $row['FileName'] . '</p>';
  echo 
'<p>File size:' $row['FileSize'] . ' KB <br />';
  echo 
'<p>File Description:' $row['Description'] . '<br />';
  
// etc...
  
echo '<br /><p style="text-align:center">Download:
      <a href="[URL="http://'
.$_SERVER['HTTP_HOST'].'/file.php?file='.$row['FileName'].'&quot;>http://'.$_SERVER['HTTP_HOST'].'/file.php?file='.$row['FileName'].'</a>'"]http://'.$_SERVER['HTTP_HOST'].'/file.php?file='.$row['FileName'].'">http://'.$_SERVER['HTTP_HOST'].'/file.php?file='.$row['FileName'].'</a>'[/URL];
}
echo 
'</div>
     </body>
     </html>'
;
mysql_close($conn);
?>


Everything else here should be fairly obvious from what you gained from previous information.
 
EDIT: Add the following, call it file.php,
Code: [Select]
<?php
require_once('config.php');
$conn mysql_connect($mysql_server$mysql_username$mysql_password);
if (!
$conn) {
    die(
'Unable to connect to database!');
}
$db mysql_select_db($mysql_db$conn);
if (!
$db) {
    die(
'Unable to select database!');
}
$query "SELECT FileType as type FROM repository WHERE ID_FILE = '$file_id'";
$result mysql_fetch_array(mysql_query($query));
$file $_GET['file'];
header("Expires: 0");
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0"false);
header("Pragma: no-cache");
header("Content-type: $result[type]");
header('Content-length: '.filesize($file));
header('Content-disposition: attachment; filename='.$file.'');
readfile($file);
exit;

mysql_close($conn);
?>

Conclusion

Anyways, I hope you have learned a lot from this long tutorial. Im glad people requested tutorials that I have had time to make, I had fun and learned a lot myself. Thanks!

 4 
 on: September 03, 2010, 03:05:25 pm 
Last post by Solsta - Started by crossfire
Read times
Solsta

Joined: Jan 1970

Reputation: 0
Posts:
 Lol even better. I will praise whoever can actually upload the entire model list onto Mediafire lol. Or maybe into 2-3 parts.

 5 
 on: September 02, 2010, 06:02:50 am 
Last post by Tom - Started by God Of Skill
Read times
Tom

Joined: Jan 1970

Reputation: 0
Posts:
No, I'm afraid not. Havenworld images are copyrighted under the GLC licence (1990 - 2010 copyright) any redistribution of these pictures is strongly prohibeted. GLC (General Licence Company) have rights to take action based on a legal/non-legal ground whever it be in a  court room or general discussions between the two boards.

GLC OV:

GLC reserves the right to take action upon copyright images whever it be Legal/Non-Legal action, GLC is a free legal team company based on remanding copyright and keeping it in original form (Which the creator intends).

In short you can't use these images without the legal permission passed of GLC or you may be taken to court. So no, I'm afraid we can't.

Topic LOCKED.

 6 
 on: September 02, 2010, 01:06:17 am 
Last post by Proxima - Started by God Of Skill
Read times
Proxima

Joined: Jan 1970

Reputation: 0
Posts:
are you retarded. please be honest.

 7 
 on: September 02, 2010, 12:25:34 am 
Last post by God Of Skill - Started by God Of Skill
Read times
God Of Skill

Joined: Jan 1970

Reputation: 0
Posts:
Post count,

Can someone post some pics i can use for post count please. or can an admin E.G Tom/Mat show me haven post count pics.

Thanks

 8 
 on: August 30, 2010, 09:48:37 pm 
Last post by Matt - Started by Tom
Read times
Matt

Joined: Jan 1970

Reputation: 0
Posts:
This is why you don't give tom pics

 9 
 on: August 30, 2010, 05:01:10 pm 
Last post by Project Evolution - Started by Project Evolution
Read times
Project Evolution

Joined: Jan 1970

Reputation: 0
Posts:
Hello, today im going to be going over a basic structure to a useful concept of integrating your SMF forum into other parts of your website. Lets start by creating a simple php page,
Code: [Select]
<html>
 
   <head>
      <title>My site - index</title>
   </head>
 
   <body>
      <?php
 
      ?>

   </body>
 
</html>

Now we have our layout of the php file with a simple title. Let me begin by explaining SMF's SSI functions. Every single one of SMF's custimizable functions can be found in a file called SSI.php in the root of the SMF package. Contained within this file is loads of functions that display recent posts, new members, news feeds, etc. You can find an example of these functions by going to a file called ssi_examples.php (and/or ssi_examples.shtml). This file is located in the same place as SSI.php, in the root of SMF's package. For example, lets say the URL to my forum is faggots.com/smf. To access this file I would simple go to, faggots.com/smf/ssi_examples.php.
 
In order to use these SSI functions, we will place a PHP require function in the file and call the SSI.php file like so,
Code: [Select]
<?php require("URL-TO-THE-SSI.PHP-FILE"); ?>
<html>
 
   <head>
      <title>My site - index</title>
   </head>
 
   <body>
      <?php
 
      ?>

   </body>
 
</html>

There are some key specific things im going to point out here. As you can see, I called the require() function above anything else in the file, why? Firstly, I use this as a personal habit to make sure I call this before trying to access anything from the file im trying to access. In my next SSI tutorial, I will explain why this should be a good habit to get into. For now, just make sure your calling the require() function before attempting to use any of SMF's SSI functions.
 
Using SSI is quite simplistic, you simple just call the functions assosciated with it.
Lets dig a little deeper than calling functions. Say for example we wanted a tab in a navigation bar to show up if we are an admin, or remove the tab entirely if we are not. Lets take a look,
Code: [Select]
         <div id="navigation">
            <ul>
                <li><a href="/">Home</a></li>
                <li><a href="/smf/">Forum</a></li>
                <li><a href="index.php?action=products">Products</a></li>
                <li><a href="index.php?action=portfolio">Portfolio</a></li>
                <li><a href="about.php">About</a></li>
                <?php
                 
global $context;
                 if (
$context['allow_admin'])
                    echo 
'<li><a href="#">Admin Panel</a></li>'?>

           </ul>
        </div>

Basically, what we need to do here is check whether or not we are an admin. Firstly, we create php tags to indicate we are going to be using PHP. We call the $context variable from SSI.php, then we create an if statement checking against whether or not we are an admin. If true, we echo the HTML which includes the 'secret' admin tab. Dont forget to create that $context variable otherwise it wont work!
 
Here is a simple function that handles a login box,
Code: [Select]
function show_login() {
    global $context;
    if ($context['user']['is_guest']) { // Check whether or not user is a guest - if so, display a login box with some extra content
        echo '<p class="title">Login</p>
            <span class="center" style="color: #FFFFFF;">', ssi_login() ,'</span>
            <br />
            <a href="http://faggots.com/smf/index.php?action=reminder">Forgot your password?</a>';
    } else { // If not - display a logout button
        echo '<p class="title">Logout</p>
            <span class="center" style="color: #FFFFFF;">', ssi_logout() ,'</span>';
    }
}

For those without SMF but interested in these functions, please see,
http://www.simplemachines.org/community/ssi_examples.php
 
You can also visit the Function DB to see the functions within SSI.php,
http://support.simplemachines.org/function_db/index.php?action=view_file;id=66
 
Thanks for reading.

 10 
 on: August 30, 2010, 12:13:12 am 
Last post by dane - Started by Tom
Read times
dane

Joined: Jan 1970

Reputation: 0
Posts:
This entire thread is spam.

Pages: [1] 2 3 ... 10
Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC | Havenworld © 2006 - 2009 Havenworld Plc | The Peoples World
Page created in 0.39 seconds.