Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:32 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.