Page 2 of 3
Posted: Thu May 13, 2004 5:44 am
by launchcode
Does the image actually upload? I.e. does it appear in the p_imgs directory? Or not?
Remove the @ before the "rename" command to see if that gives you an error.
Posted: Thu May 13, 2004 10:33 am
by mikewooten
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
Posted: Thu May 13, 2004 11:07 am
by launchcode
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:
Code: Select all
move_uploaded_file($_FILES['ItemImage]['tmp_name'], '/home/username/public_html/wootenmusic7/p_imgs/' . $_FILES['ItemImage']['name']);
Posted: Thu May 13, 2004 11:48 am
by mikewooten
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
Posted: Thu May 13, 2004 11:59 am
by launchcode
Get rid of the "Directory must be writable" check, if it isn't - move_uploaded_file will tell you as much.
If there was no error issued by the move_uploaded_file function then it will have moved it successfully. It would crap out with errors all over the place otherwise.
Posted: Thu May 13, 2004 7:18 pm
by mikewooten
i got rid of the "Directory must be writable" line, i viewed the file again and when i ran the page, it gave me a message saying that the upload failed. its not uploading the image?
should i post my updated code that i have?
what else should i try to get this to work?
thanks
Posted: Thu May 13, 2004 8:06 pm
by mikewooten
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
?
Posted: Thu May 13, 2004 11:10 pm
by mikewooten
?
Posted: Fri May 14, 2004 5:36 am
by launchcode
Why did you change that part? The name after the $_FILES statement has to match *exactly* the name of the <input type=file> element on your original form. If it doesn't, it doesn't have a snowballs chance in hell of working.
Posted: Fri May 14, 2004 8:23 am
by mikewooten
when i viewed the page, it gave me a message saying that the upload failed. its not uploading the image?
should i post my updated code that i have?
what else should i try to get this to work?
thanks
Posted: Fri May 14, 2004 8:36 am
by launchcode
I think that might be best!
Posted: Fri May 14, 2004 8:44 am
by mikewooten
here's my new updated code that i have:
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";
}
?>
?>
?
Posted: Fri May 14, 2004 11:18 am
by mikewooten
?
Posted: Fri May 14, 2004 1:14 pm
by mikewooten
can anyone help me with what i would need to do to my code in order for this to work. when i view the file, it says that the upload failed. does anyone know why it would fail with the code that i am using?
and why the upload is failing when the upload was working before?
thanks
?
Posted: Fri May 14, 2004 4:10 pm
by mikewooten
? is there anyone who will help?
any help would be much appreciated
thank you
thanks