need help with upload image and getting image name to databa
Moderator: General Moderators
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
i checked the path on my server to see if the image has uploaded, and its not uploading, i don't know why, it was uploading before.?
also i have removed the @ before the rename and it gave me this error:
Warning: rename(/tmp/phpd9WwNR,/home/username/public_html/wootenmusic7/p_imgs/car27.jpg): No such file or directory in /home2/username/public_html/admintest/add3_1_3.php on line 72
The Directory "/home/username/public_html/wootenmusic7/p_imgs/" must be writeable!
insert into items (prodItems, catid, itemName, itemDesc, itemPrice, ItemImage) values ('Guitars', '0', '28', '28', '28', 'car27.jpg')
should i put the @ back in and/or should i put this back in
$theSQL = $theSQL . " values ('$txtprodItems', '$txtCatID', '$txtItemName', '$txtItemDesc', '$txtItemPrice', '{$_FILES['ItemImage']['name']}')";
?
thanks
also i have removed the @ before the rename and it gave me this error:
Warning: rename(/tmp/phpd9WwNR,/home/username/public_html/wootenmusic7/p_imgs/car27.jpg): No such file or directory in /home2/username/public_html/admintest/add3_1_3.php on line 72
The Directory "/home/username/public_html/wootenmusic7/p_imgs/" must be writeable!
insert into items (prodItems, catid, itemName, itemDesc, itemPrice, ItemImage) values ('Guitars', '0', '28', '28', '28', 'car27.jpg')
should i put the @ back in and/or should i put this back in
$theSQL = $theSQL . " values ('$txtprodItems', '$txtCatID', '$txtItemName', '$txtItemDesc', '$txtItemPrice', '{$_FILES['ItemImage']['name']}')";
?
thanks
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
Well you can spot the error far more easily now! Look at thar rename function - no wonder it doesn't work.
You should really use move_uploaded_file rather than a rename function anyway, try this:
You should really use move_uploaded_file rather than a rename function anyway, try this:
Code: Select all
move_uploaded_file($_FILES['ItemImage]['tmp_name'], '/home/username/public_html/wootenmusic7/p_imgs/' . $_FILES['ItemImage']['name']);-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
i changed the rename function to:
if(move_uploaded_file($_FILES['ItemImage']['tmp_name'],$path.$_FILES['txtItemImage']['name']))
and it got rid of the error, but it still displays this:
The Directory "/home/username/public_html/wootenmusic7/p_imgs/" must be writeable!
insert into items (prodItems, catid, itemName, itemDesc, itemPrice, ItemImage) values ('Guitars', '0', '30', '30', '30', 'car30.jpg')
and the image is still not uploading into the directory? i don't know why?
the directory should be writeable, i have the correct permissions on that folder.
what else should i try for the image to upload and display and for the "The Directory must be writeable!" message not show up?
thanks
if(move_uploaded_file($_FILES['ItemImage']['tmp_name'],$path.$_FILES['txtItemImage']['name']))
and it got rid of the error, but it still displays this:
The Directory "/home/username/public_html/wootenmusic7/p_imgs/" must be writeable!
insert into items (prodItems, catid, itemName, itemDesc, itemPrice, ItemImage) values ('Guitars', '0', '30', '30', '30', 'car30.jpg')
and the image is still not uploading into the directory? i don't know why?
the directory should be writeable, i have the correct permissions on that folder.
what else should i try for the image to upload and display and for the "The Directory must be writeable!" message not show up?
thanks
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
i also changed
if(move_uploaded_file($_FILES['ItemImage']['tmp_name'],$path.$_FILES['txtItemImage']['name']))
to this
if(move_uploaded_file($_FILES['txtItemImage']['tmp_name'],$path.$_FILES['txtItemImage']['name']))
the part that i changed was $_FILES['ItemImage'] to $_FILES['txtItemImage']
when i did that i got this error
Warning: move_uploaded_file(/home/username/public_html/wootenmusic7/p_imgs/car34.jpg): failed to open stream: No such file or directory in /home2/username/public_html/wootenmusic7/admintest/add3_1_3.php on line 73
Warning: move_uploaded_file(): Unable to move '/tmp/phpcfp1sE' to '/home/username/public_html/wootenmusic7/p_imgs/car34.jpg' in /home2/username/public_html/wootenmusic7/admintest/add3_1_3.php on line 73
Upload failed!
insert into items (prodItems, catid, itemName, itemDesc, itemPrice, ItemImage) values ('Guitars', '0', '34', '34', '34', 'car34.jpg')
the part that i don't understand about the error, is why is it giving me the output on the beginning of the path of home2 instead of home?
thanks
if(move_uploaded_file($_FILES['ItemImage']['tmp_name'],$path.$_FILES['txtItemImage']['name']))
to this
if(move_uploaded_file($_FILES['txtItemImage']['tmp_name'],$path.$_FILES['txtItemImage']['name']))
the part that i changed was $_FILES['ItemImage'] to $_FILES['txtItemImage']
when i did that i got this error
Warning: move_uploaded_file(/home/username/public_html/wootenmusic7/p_imgs/car34.jpg): failed to open stream: No such file or directory in /home2/username/public_html/wootenmusic7/admintest/add3_1_3.php on line 73
Warning: move_uploaded_file(): Unable to move '/tmp/phpcfp1sE' to '/home/username/public_html/wootenmusic7/p_imgs/car34.jpg' in /home2/username/public_html/wootenmusic7/admintest/add3_1_3.php on line 73
Upload failed!
insert into items (prodItems, catid, itemName, itemDesc, itemPrice, ItemImage) values ('Guitars', '0', '34', '34', '34', 'car34.jpg')
the part that i don't understand about the error, is why is it giving me the output on the beginning of the path of home2 instead of home?
thanks
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
?
?
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
here's my new updated code that i have:
what should i try for this to work?
thanks
what should i try for this to work?
thanks
Code: Select all
<?php
<?
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
?>
<?php echo "<?xml version="1.0" encoding="iso-8859-1"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<META HTTP-EQUIV='Pragma' CONTENT='no-cache' />
<META HTTP-EQUIV='Cache-Control' CONTENT='no-cache' />
</head>
<body>
<form action="<? $_SERVER['PHP_SELF']; ?>" method="post" ENCTYPE="multipart/form-data">
Choose a product category <br>
<select name="txtCatID" id="select">
<option value="0" SELECTED>0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><br>
Choose product items to add to your product pages <br>
<input type="hidden" name="<?echo '$txtCatID';?>">
<select name="txtprodItems" id="select">
<option value="Guitars" SELECTED>Guitars</option>
<option value="Drums">Drums</option>
<option value="Amps">Amps</option>
<option value="Books">Books</option>
</select><br>
item name<br>
<input type="text" name="txtItemName"><br>
item description<br>
<input type="text" name="txtItemDesc"><br>
item price<br>
<input type="text" name="txtItemPrice"><br>
<?
//START DB Stuff Here////////////////
// specify the directory where the uploaded file should end up
$path = "/home/username/public_html/wootenmusic7/p_imgs/";
// specify the filetypes allowed
$allowed = array('image/gif','image/pjpeg','image/jpeg','image/png');
// specify the max filesize in bytes
$max_size = 200000;
if(isset($_FILES['txtItemImage']))
{
if(is_uploaded_file($_FILES['txtItemImage']['tmp_name']))
{
if($_FILES['txtItemImage']['size'] < $max_size)
{
if(in_array($_FILES['txtItemImage']['type'],$allowed))
{
if(!file_exists($path . $_FILES['txtItemImage']['name']))
{
if(move_uploaded_file($_FILES['ItemImage']['tmp_name'],$path.$_FILES['txtItemImage']['name']))
{
$html_output = 'Upload sucessful!<br>';
$html_output .= 'File Name: '.$_FILES['txtItemImage']['name'].'<br>';
$html_output .= 'File Size: '.$_FILES['txtItemImage']['size'].' bytes<br>';
$html_output .= 'File Type: '.$_FILES['txtItemImage']['type'].'<br>';
$image = $_FILES['txtItemImage']['name'] ;
}else{
$html_output = 'Upload failed!<br>';
if(!is_writeable($path))
{
//$html_output = 'The Directory "'.$path.'" must be writeable!<br>';
}else{
$html_output = 'an unknown error ocurred.<br>';
}
}
}else{
$html_output = 'The file already exists<br>';
}
}else{
$html_output = 'Wrong file type<br>';
}
}else{
$html_output = 'The file is too big<br>';
}
}
}else{
$html_output = '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">';
$html_output .= '<input type="file" name="txtItemImage">';
$html_output .= '<input type="submit" name="submit" value="upload"><input type="Reset" />';
$html_output .= '</form>';
}
echo '<html><head><title>Uploader</title></head><body>';
echo $html_output;
echo '</body></html>';
$html_output = $_POST['submit'];
if(isset($html_output)){
include("db2.php");
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$txtCatID = $_POST['txtCatID'];
$txtprodItems = $_POST['txtprodItems'];
$txtItemName = $_POST['txtItemName'];
$txtItemDesc = $_POST['txtItemDesc'];
$txtItemPrice = $_POST['txtItemPrice'];
$txtItemImage = $_FILES['txtItemImage']['name'];
echo "$theSQL";
$theSQL = "insert into items (prodItems, catid, itemName, itemDesc, itemPrice, ItemImage)";
$theSQL = $theSQL . " values ('$txtprodItems', '$txtCatID', '$txtItemName', '$txtItemDesc', '$txtItemPrice', '$txtItemImage')";
$result = mysql_query($theSQL);
echo "$theSQL";
}else{
echo "did not insert any image into database";
}
?>
?>-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
?
?
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
-
mikewooten
- Forum Contributor
- Posts: 169
- Joined: Wed Feb 11, 2004 12:13 pm
- Location: Duluth, Georgia
- Contact:
?
? is there anyone who will help?
any help would be much appreciated
thank you
thanks
any help would be much appreciated
thank you
thanks