This is a mini social project. You can add friends, edit personal profile, upload image, post your daily life, comment to posts, search users, and check whether friend is online
NOTICE: This project using remote database (RDS) and AWS S3 for images store. If you want to run in local, you must configure some files.
-
change db.php file, modify
$servername
,$username
,$password
and$dbname
according to your own database. -
change controller/photo-action file, modify
$target_dir="img/"
to set all pictures stored in img folder. delete following code:try{ //upload to S3 $result = $client->putObject(array( 'Bucket' => $bucket, 'Key' => $imagename, 'Body' => fopen($_FILES['uploadimage']['tmp_name'], 'r+'), 'options' => [ 'scheme' => 'http', ], )); } catch (Exception $e) { exit($e->getMessage()); }
and replace it with
move_uploaded_file($_FILES['uploadimage']['tmp_name'], $imagename);
modify
$targetPath
to$targetPath=$imagename
-
change controller/profile-action.php file, delete the following code:
try{ //upload to S3 $result = $client->putObject(array( 'Bucket' => $bucket, 'Key' => $headshot, 'Body' => fopen($_FILES['headshot']['tmp_name'], 'r+'), )); } catch (Exception $e) { exit($e->getMessage()); }
and uncomment the following code block. modify$targetPath
to $targetPath=$headshot
.
If you have your own AWS account and want to deploy RDS and S3, you still need to configure some files.
- if you want to connect RDS to your phpmyadmin, edit php configuration file bin/phpMyAdmin/config.inc.php. Add following code and your own RDS URL in
server(s) configuration
block:
$i++;
$cfg['Servers'][$i]['host'] = 'your own RDS URL';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['compress'] = TRUE;
Restart PHP server after configuration.
- change db.php, modify
$servername
,$username
,$password
and$dbname
according to your own RDS.
-
I strongly recommand to configure aws credential file to store your access key instead of hard code. For crediential file, refer to http://docs.aws.amazon.com/aws-sdk-php/v2/guide/credentials.html#credential-profiles. If you currently do not have aws hidden folder, you can create it in computer's home folder (c:\ for Windows, Macintosh HD for MAC) yourself. In addition, according to S3.php, the access key should be placed under [project1] section in credentials file.
-
On the other hand, if you want to connect to S3 with hard code, you can replace code in s3.php with following code and paste access key in it:
<?php require 'aws/vendor/autoload.php'; use Aws\S3\S3Client ; use Aws\S3\Exception\S3Exception; try{ $client = S3Client::factory(array( 'credentials' => array( 'key' => 'your access key ID', 'secret' => 'your access secret key', ), 'version' => '2006-03-01', 'region' => 'us-west-2' )); } catch(Exception $e) { exit($e->getMessage()); } //S3 bucket name $bucket = 'minisocial'; ?>
-
In S3, a bucket named minisocial should be created for storing, if you want to create bucket in another name, edit
$bucket
in S3.php file. Besides, According your S3 URL and bucket name, edit$targetPath
in controller/profile-action.php, controller/photo-action.php, register-action.php, and"s3path"
in upload.php. -
For folder used to stored pictures in AWS S3 bucket, create /img for saving user headshot and /postdata for saving post picture.