Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //connect to database
- require('dbConnect.php');
- // Grab the profile data from the database
- if (!isset($_POST['username'])) {
- $query = "SELECT username, firstName, lastName, city, state, country, email, bio FROM capstone WHERE username = '$username'";
- }
- else {
- $query = "SELECT username, firstName, lastName, city, state, country, email, bio FROM capstone WHERE username = '" . $_POST['username'] . "'";
- }
- $data = mysqli_query($dbc, $query);
- if (mysqli_num_rows($data) == 1) {
- // The user row was found so display the user data
- $row = mysqli_fetch_array($data);
- echo '<table>';
- if (!empty($row['username'])) {
- echo '<tr><td class="label">Username:</td><td>' . $row['username'] . '</td></tr>';
- }
- if (!empty($row['firstName'])) {
- echo '<tr><td class="label">First name:</td><td>' . $row['firstName'] . '</td></tr>';
- }
- if (!empty($row['lastName'])) {
- echo '<tr><td class="label">Last name:</td><td>' . $row['lastName'] . '</td></tr>';
- }
- if (!empty($row['city']) || !empty($row['state']) || !empty($row['country'])) {
- echo '<tr><td class="label">Location:</td><td>' . $row['city'] . ', ' . $row['state'] . ' ' . $row['country'] . '</td></tr>';
- }
- if (!empty($row['email'])) {
- echo '<tr><td class="label">Email:</td><td>' . $row['email'] . '</td></tr>';
- }
- if (!empty($row['bio'])) {
- echo '<tr><td class="label">Bio:</td><td>' . $row['bio'] . '</td></tr>';
- }
- echo '</table>';
- if (!isset($_GET['user_id']) || ($user_id == $_GET['user_id'])) {
- echo '<p>Would you like to <a href="editProfile.php">edit your profile</a>?</p>';
- }
- // End of check for a single row of user results
- else {
- echo '<p class="error">There was a problem accessing your profile.</p>';
- }
- }
- ?>
- <script>
- $("form").submit(function(e){ //when form submit, trigger this function
- e.preventDefault(); //prevent form from submitting
- var formData = new FormData($(this)[0]);//grab what would've been submitted
- formData.append("submit",true); //"fake" pressing submit button
- $.ajax({url: "includes/gallery.php",
- type: "POST",
- data: formData,
- success: function(result){
- $("#dynamicContent").html(result);
- },
- error: function(result){
- $("#dynamicContent").html("Error!");
- },
- cache: false,
- contentType: false,
- processData: false,
- enctype: 'multipart/form-data'
- });
- });
- </script>
- <?php
- $errors = array();
- // image and thumbnail directories
- $target_path = "../users/$_POST['username']";
- $thumb_path = "../users/$_POST['username']/thumbs";
- //set thumbnail size
- $thumb_width = 200;
- $thumb_height = 160;
- $dir = "../users/$_POST['username']";
- //opens directory
- if ($opendir = opendir($dir)){
- //reads directory
- while ($file = readdir($opendir)){
- if ($file != "." && $file != "..")
- echo "<a href='$dir/$file'><img src='$thumb_path/$file'></a><br>";
- }
- }
- //checks the name of the file uploaded and prints it out
- if(!empty($_FILES['pictureFile']['name'])){
- // php stores everything in a temp file
- if (move_uploaded_file($_FILES['pictureFile']['tmp_name'], $target_path."/" . $_FILES['pictureFile']['name']) === FALSE)
- echo "Could not move uploaded file to ".$target_path . htmlentities($_FILES['pictureFile']['name']) . "\"<br />\n";
- else{
- //thumbnail creator
- $fileName = $_FILES['pictureFile']['name'];
- $fileExplode = explode(".", $fileName);
- $file_ext = $fileExplode[count($fileExplode)-1]; //get extension
- $upload_image = $target_path."/".basename($fileName);
- $thumbnail = $thumb_path."/".$fileName;
- list($width, $height) = getimagesize($upload_image);
- $thumb_create = imagecreatetruecolor($thumb_width, $thumb_height);
- switch($file_ext){
- case 'jpg':
- $source = imagecreatefromjpeg($upload_image);
- break;
- case 'jpeg':
- $source = imagecreatefromjpeg($upload_image);
- break;
- case 'png':
- $source = imagecreatefrompng($upload_image);
- break;
- case 'gif':
- $source = imagecreatefromgif($upload_image);
- break;
- default:
- $errors[] = "Did not submit a valid image file";
- break;
- }
- imagecopyresized($thumb_create, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
- switch($file_ext){
- case 'jpg' || 'jpeg':
- imagejpeg($thumb_create, $thumbnail, 100);
- break;
- case 'png':
- imagepng($thumb_create, $thumbnail, 100);
- break;
- case 'gif':
- imagegif($thumb_create, $thumbnail, 100);
- break;
- default:
- imagejpeg($thumb_create, $thumbnail, 100);
- }
- echo "Successfully uploaded ".$target_path." " . htmlentities($_FILES['pictureFile']['name']) . "\"<br />\n";
- }
- }
- ?>
- <form method="post" enctype="multipart/form-data" action="">
- <input type="file" name="pictureFile"/>
- <input type="submit" name="submit" value="Upload"/>
- </form>
- <?php
- //checking for errors
- if (isset($_POST["submit"])){
- $errors = array();
- if (empty($file))
- $errors[] = "No file was chosen.";
- if (count($errors) > 0 ){
- foreach ($errors as $error)
- echo "Error: ".$error."<br/>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement