I will teach you how to create a basic script that allow people to upload files and stores details of their uploads in a database. Follow up, it is not hard at all…. If you have questions, feel free to ask
First we need to create the database table with the following SQL:
CREATE TABLE `uploads` (
`id` int(10) unsigned NOT NULL auto_increment,
`whenuploaded` datetime NOT NULL default '0000-00-00 00:00:00',
`ipaddress` varchar(15) NOT NULL default 'unknown',
`imageloc` varchar(255) NOT NULL default 'unknown',
`imagesize` int(10) unsigned default NULL,
`imagetype` varchar(30) default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;
Then here’s the PHP code you need at the top of the page where you’re going to have your upload form. You need to change the database access details at the top and the ‘defines’ to specify your domain and path names. Create the DEST_DIR directory on the server with 777 permissions.
Read more…
Share on Facebook
Categories: php & mysql Tags: bmp, code, create, domain, extension, file, jpg, mysql, path, permission, php, script, tutorial, upload
Create a file for Login and Logout (PHP + MySQL) using with a SESSION variable. This file contains Login form, Login authorize program and Logout program. All in one but Short and Easily.
This tutorial require 2 PHP files and 1 table of mySQL database.
- index.php this file is the Login and Logout file.
- main.php this file is the target when login is O.K.
- Database “tutorial” and table “admin” with 3 fields: id(auto_increment), username(varchar, 50), password(varchar, 32).
* The “password” field is design for md5() password for more sucurity.Then put a record into this table. In this tutorial, put a record with name “admin” and password “81dc9bdb52d04dc20036dbd8313ed055“. This password was encrypted by md5() function from the real password “1234“.
* When you test this script you must to put the real password (1234) in “password” box.
index.php
The mainly file for do 3 things.
- Login form. Including 2 fields “username” and “password” and submit button “Login”.
- Login authorize program. Do authorize check after you submit form, if passed in username and password, this page will re-direct to main.php. If not, show the invalid user or password message.
- Logout. Clear the login session when come back or refresh this page.
Read more…
Share on Facebook