 |
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
 | This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 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
|
|
|
|

October 13th, 2010, 10:18 AM
|
|
Authorized User
|
|
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
chapter 7 check_image.php
Hi,
Can someone help me with this. This is the try this code on page 179. I keep getting a parse error for the if statement and I can't figure out the error. Thanks
error
Parse error: syntax error, unexpected T_IF in /home/content/h/u/z/huzsak/html/admin/check_image.php on line 19
code
PHP Code:
//change this path to match your images directory
$dir='http://www.admin.pctoolmanconsulting.com/images'
//make sure the uploaded file tranfer was succesful
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 exceed the MAX_FILE_SIZE directive that ' . 'was specified in the HTML form.');
break;
case UPLOAD_ERR_PARTIAL:
die('The uploaded file waas 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 the disk.');
break;
case UPLOAD_ERR_EXTENSION:
die('File upload stopped by extension.');
break;
}
}
//get information 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 uploaded file is really a supported image
switch ($type) {
case IMAGETYPE_GIF:
$image = imagecreatefromgif($_FILES['uploadfile']['tmp_name']) or
die('The file you uploaded was not a supported filetype.');
$ext = '.gif';
break;
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']) or
die('The file you uploaded was not a supported filetype.');
$ext = '.jpg';
break;
case IMAGETYPE_PNG
$image = imagecreatefrompng($_FILES['uploadfile']['tmp_name']) or
die('The file you uploaded was not a supported filetype');
$ext = '.png';
break;
default:
die('The file you uploaded was not a supported filetype');
}
//insert information into image table
$query = 'INSERT INTO images
(image_caption, image_username, image_date)
VALUES
("' . $image_option . '", "' . $image_username . '", "' . $image_date . '")';
$results=mysql_query($query) or die (mysql_error());
//retrieve the image_id that MYSQL generated automatically when we inserted
//the new record
$last_id = mysql_insert_id();
//because the is is unique. we can use it as the image name as well to make
//sure we dont overwrite another image that already exists
$imagename = $last_id . $ext;
//update the image table now that the final filename is known.
$query = 'UPDATE images
SET image_filename = "' . $imagename . '"
WHERE image_id = ' . $last_id;
$results=mysql_query($query) or die (mysql_error());
//save the image to its final destination
switch ($type) {
case IMAGETYPE_GIF:
imagegif($image, $dir . '/' . $imagename);
break;
case IMAGETYPE_JPEG
imagejpeg($image, $dir . '/' . $imagename, 100);
break
case IMGAGETYPE_PNG
imagepng($image, $dir . '/' . $imagename);
break;
)
imagedestroy($image);
?>
<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="images/<?php echo $imagename; ?>" style="float:left;">
<table>
<tr><td>Image Save as: </td><td><?php echo $imagename; ?></td></tr>
<tr><td>Image Type:</td><td><?php echo $ext; ?></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>
|
|

December 24th, 2010, 05:02 AM
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re-parse error-unexpected T-if
If it is an unexpected "If" then check the program flow of an unended "if" or an "if" without a reason. This is a common parse error with a wrongly used code "selection".
Besides, the code on this particular script in chapter 07 has a number of errata. As it does not run as such..so you really have to do some serious modification on it b4 it gives the proper output.
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Chapter 3 - PHP |
fixxxer125 |
BOOK: CSS Instant Results |
2 |
October 18th, 2007 02:14 PM |
| chapter 10 Emailing with php - firstmail.php |
vijdev |
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 |
0 |
July 19th, 2007 01:12 AM |
| Ch 7 check_image.php |
mattcw |
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 |
1 |
October 10th, 2006 12:26 PM |
| begin php & mysql - chapter 12, user_form.php |
jon_stubber |
Beginning PHP |
1 |
March 9th, 2006 10:57 AM |
| Chapter 7 check_image.php, undefined variable |
Ron_Bingham |
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 |
2 |
June 3rd, 2005 10:31 PM |
|
 |