Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 17th, 2014, 09:46 AM
Registered User
 
Join Date: Jul 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default I have inserted images in a folder but i am unable to retrive images from it

<?php
//connect to MySQL
$db = mysql_connect('localhost', 'root', 'jayant') or
die ('Unable to connect. Check your connection parameters.');
mysql_select_db('moviesite', $db) or die(mysql_error($db));

//change this path to match your images directory
$dir ='C:\Users\SONY\Desktop\images';

//make sure the uploaded file transfer was successful
if ($_FILES['uploadfile']['error'] != UPLOAD_ERR_OK)
{
switch ($_FILES['uploadfile']['error']) {
case UPLOAD_ERR_INI_SIZE:
die('The uploaded file exceeds the upload_max_filesize directive ' .
'in php.ini.');
break;
case UPLOAD_ERR_FORM_SIZE:
die('The uploaded file exceeds the MAX_FILE_SIZE directive that ' .
'was specified in the HTML form.');
break;
case UPLOAD_ERR_PARTIAL:
die('The uploaded file was only partially uploaded.');
break;
case UPLOAD_ERR_NO_FILE:
die('No file was uploaded.');
break;
case UPLOAD_ERR_NO_TMP_DIR:
die('The server is missing a temporary folder.');
break;
case UPLOAD_ERR_CANT_WRITE:
die('The server failed to write the uploaded file to disk.');
break;
case UPLOAD_ERR_EXTENSION:
die('File upload stopped by extension.');
break;
}
}

//get info about the image being uploaded
$image_caption = $_POST['caption'];
$image_username = $_POST['username'];
$image_date = @date('Y-m-d');
list($width, $height, $type, $attr) =
getimagesize($_FILES['uploadfile']['tmp_name']);

// make sure the uploaded file is really a supported image
$error = 'The file you uploaded was not a supported filetype.';
switch ($type) {
case IMAGETYPE_GIF:
$image = imagecreatefromgif($_FILES['uploadfile']['tmp_name']) or
die($error);
$ext='.gif';
break;
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']) or
die($error);
$ext='.jpg';
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng($_FILES['uploadfile']['tmp_name']) or
die($error);
$ext='.png';
break;
default:
die($error);
}

//insert information into image table
$query = 'INSERT INTO images
(image_caption, image_username, image_date)
VALUES
("' . $image_caption . '", "' . $image_username . '", "' . $image_date .'")';

$result = mysql_query($query, $db) or die (mysql_error($db));

//retrieve the image_id that MySQL generated automatically when we inserted
//the new record
$last_id = mysql_insert_id();
$imagename = $last_id .$ext;
// save the image to its final destination
$image_id = $last_id;
$query = 'Update images SET image_filename ="'.$imagename.'" WHERE image_id ='.$last_id;
$result = mysql_query($query, $db) or die (mysql_error($db));
// save the image to its final destignation
switch($type) {
case IMAGETYPE_GIF:
imagegif($image ,$dir .'/'. $imagename);
break;
case IMAGETYPE_JPEG:
imagejpeg($image ,$dir.'/'. $imagename , 100) ;
break;
case IMAGETYPE_PNG:
imagepng($image ,$dir .'/'. $imagename);
break;
default:
die('Not supported');
}

?>

<html>
<head>
<title>Here is your pic!</title>
</head>
<body>

<h1>So how does it feel to be famous?</h1>
<p>Here is the picture you just uploaded to our servers:</p>

<img src="<?php echo $imagename; ?>" style="float:left;">
<table>
<tr><td>Image Saved as: </td><td><?php echo $imagename ?></td></tr>
<tr><td>Height: </td><td><?php echo $height; ?></td></tr>
<tr><td>Width: </td><td><?php echo $width; ?></td></tr>
<tr><td>Upload Date: </td><td><?php echo $image_date; ?></td></tr>
</table>


</body>
</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Corporate Images Folder Not Found! sprdave BOOK: Beginning SharePoint 2007: Building Team Solutions with MOSS 2007 ISBN: 978-0-470-12449-9 2 April 19th, 2008 08:00 PM
Get images from folder surendran ActionScript 1 December 12th, 2007 11:55 PM
retrive images from a database vindya0121 VB Databases Basics 0 March 23rd, 2006 07:30 AM
images folder Lee jonesy Dreamweaver (all versions) 7 September 12th, 2004 01:35 PM
Random images straight from folder dsunmedia PHP How-To 1 July 21st, 2004 01:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.