Wrox Programmer Forums
|
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 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 14th, 2010, 11:57 PM
Authorized User
 
Join Date: Feb 2010
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default move_uploaded_file frustration

Hey there,

I am trying to build a film scouts website where the website manager can upload images and text. I have modified your chapter 13 transact-article to achieve the text side of things and am now trying to incorporate your chapter 7 image uploading script. I have sucessfully got the script working as written in the book but i can't get it to connect to the datbase when it is inserted into the transact article page. I have narrowed it down to the if (move_uploaded_file.. part of the script. If I comment this and the closing parentheses the script connects and adds the information to the script (however doesn't obviously move the image to the folder). If I leave this in it simply won't connect to the database. I had to modify the script in order to achieve the connection as the database part of check_image.php doesn't work either. any thoughts? below is the script as it sits in my page:



<?php
session_start();
require_once 'conn.php';
require_once 'http.php';

if (isset($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
case 'Upload Image':

$image_tempname = $_FILES['image_filename']['name'];
$ImageDir ="img/dbimg/";
$ImageName = $ImageDir . $image_tempname;

if (move_uploaded_file($_FILES['image_filename']['tmp_name'],
$ImageName)) {

list($width, $height, $type, $attr) = getimagesize($ImageName);

switch ($type) {
case 1:
$ext = ".gif";
break;
case 2:
$ext = ".jpg";
break;
case 3:
$ext = ".png";
break;
default:
echo "Sorry, but the file you uploaded was not a GIF, JPG, or " .
"PNG file.<br>";
echo "Please hit your browser's 'back' button and try again.";
}

$sql = "INSERT INTO cms_images " .
"(image_caption, image_username, page_id, image_date) " .
"VALUES ('" . $_POST['image_caption'] .
"','" . $_POST['pageid'] .
"'," . $_SESSION['user_id'] . ",'" .
date("Y-m-d H:i:s", time()) . "')";

mysql_query($sql, $conn)
or die('Could not insert content; ' . mysql_error());

$lastpicid = mysql_insert_id();

$newfilename = $ImageDir . $lastpicid . $ext;

rename($ImageName, $newfilename);

}

if ($_POST['pageid'] == 'crew') {
redirect('crew.php?imageupload=yes');
break;
}
}

} else {
redirect('index.php');
}
?>

Thanks for help in advance.
 
Old February 18th, 2010, 07:59 AM
Authorized User
 
Join Date: Feb 2010
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey there,

Another typo - should really try to read my code more carefully!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Frustration with VB Editor jeremy1048 Access 3 October 26th, 2007 01:10 PM
Problem with move_uploaded_file arimakidd PHP Databases 1 October 29th, 2006 09:49 PM
using a expression causing frustration s.wright Access VBA 1 July 26th, 2006 03:37 PM
ComboBox Mayhem Frustration. snw C# 1 November 28th, 2005 05:06 AM





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