| | |
Php upload photos script
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2009
Posts: 8
Reputation:
Solved Threads: 0
Hi im having abit of trouble adapting a tutorial i found on nettuts for creating a photography website heres the link if you wanna check it out:
http://net.tutsplus.com/videos/scree...-a-photo-site/
Anyways this code is fine, although because i have several categories of photos i need to store them in seperate tables, was wondering if i could use a drop down box to let the user choose the table where they want the photos to go. Any help is greatly appreciated.
ive posted the code below for the admin page. i included the select box i just dont have a clue on the php side of things thanks again.
http://net.tutsplus.com/videos/scree...-a-photo-site/
Anyways this code is fine, although because i have several categories of photos i need to store them in seperate tables, was wondering if i could use a drop down box to let the user choose the table where they want the photos to go. Any help is greatly appreciated.
ive posted the code below for the admin page. i included the select box i just dont have a clue on the php side of things thanks again.
php Syntax (Toggle Plain Text)
<?php require 'config.php'; require 'functions.php'; require 'common.php'; if(isset($_FILES['fupload'])) { $filename = addslashes($_FILES['fupload']['name']); //get image user inputs $source = $_FILES['fupload']['tmp_name']; // temp directory where image is stored $target = $path_to_image_directory . $filename; $description = addslashes($_POST['description']); $src = $path_to_image_directory . $filename; $tn_src = $path_to_thumbs_directory . $filename; // Validates the form input if(strlen($_POST['description']) < 5) // validates user inputted something larger than 5 characters long $error['description'] = '<p class="alert">Please enter a description for the photo. </p>'; if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename)) // check user chose a picture to upload $error['no_file'] = '<p class="alert">Please select an image to upload </p>'; if(!$error) { move_uploaded_file($source, $target); // move image from temporary directory $q = "INSERT into photo(description, src, tn_src) VALUES('$description', '$src', '$tn_src')"; //update database $result = $mysqli->query($q) or die(mysqli_error($mysqli)); if($result) { echo "Your Photograph has been uploaded"; } createThumbnail($filename); } // end preg_match } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="css/default.css" /> <title>My Photos</title> </head> <body> <h1>My Photos</h1> <ul><?php getPhotos(); ?></ul> <h1>Upload a Photo</h1> <form enctype="multipart/form-data" method="post" action="admin.php"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <p><input type="file" name="fupload" /></p> <p><label for="description">Enter a Description: </label> <textarea rows="6" cols="50" id="description" name="description"></textarea></p> <p> <select name="catagory"> <option value="sports">Sports</option> <option value="london">London</option> <option value="macro">Macro</option> <option value="landscapes">Landscapes</option> <option value="local">Local</option> </select> <p><input type="submit" value="Upload Photo" name="submit" /></p> </form> <?php if ($error['no_file']) echo $error['no_file']; if ($error['no_catagory']) echo $error['no_catagory']; if ($error['description']) echo $error['description']; ?> <br /> <a href="deletephoto.php">Delete A Photo</a> </body> </html>
Last edited by peter_budo; Mar 21st, 2009 at 3:40 pm. Reason: Please use [code][/code] instead of <code></code>
hi this is nathen i think this is usefull some what for you,
php Syntax (Toggle Plain Text)
$uploaddir="uploads/deals/"; $filetype1=$_FILES[userfile][type]; $filename=$_FILES[userfile][name]; $realpath=$uploaddir.$filename; if(!empty($filetype1)) { if(move_uploaded_file($_FILES['userfile']['tmp_name'],$realpath )) { } /************************************Resizing the image 75x75****************/ $path="uploads/deals"; $bgim_file_name = $path."/".$filename; $bgimage_attribs = getimagesize($bgim_file_name); if($filetype1=='image/gif') { $bgim_old = imagecreatefromgif($bgim_file_name); } else { $bgim_old = imagecreatefromjpeg($bgim_file_name); } $bgth_max_width = 75; //for Album image $bgth_max_height = 75; $bgratio = ($bgwidth > $bgheight) ? $bgth_max_width/$bgimage_attribs[0] : $bgth_max_height/$bgimage_attribs[1]; $bgth_width = 75;//$image_attribs[0] * $ratio; $bgth_height = 75;//$image_attribs[1] * $ratio; $bgim_new = imagecreatetruecolor($bgth_width,$bgth_height); imageantialias($bgim_new,true); $bgth_file_name = "uploads/deals/thumbnails/$filename"; imagecopyresampled($bgim_new,$bgim_old,0,0,0,0,$bgth_width,$bgth_height, $bgimage_attribs[0], $bgimage_attribs[1]); if($filetype1=='image/gif') { imagegif($bgim_new,$bgth_file_name,100); } else { imagejpeg($bgim_new,$bgth_file_name,100); } }
Last edited by peter_budo; Mar 26th, 2009 at 11:15 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
![]() |
Similar Threads
- Php script for upload photos (PHP)
- php web album (PHP)
- using drop down menu with to insert data through php (PHP)
- Cant upload mp3's with this script? (PHP)
- upload (PHP)
- Dummy asks: how can i? (PHP)
- Need help with directory displayer code (PHP)
Other Threads in the PHP Forum
- Previous Thread: php newsletter
- Next Thread: Message to be called on the same page in php
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend





