I have a form that uploads 3 .jpg's to a folder and lists the names of the .jpg's in a database table. It works fine unless I try to strip off the ".jpg" from the end of the image name.
This is what it does. example. if image name is "imgname.jpg" and the database fields are image1,image2,image3.
image1 image2 image3
. j p
should be:
image1 image2 image3
imgname imgname imgname
instead of giving me the name of each image with out the ".jpg"
Any help is appreciated.
thanks in advance..
here is my code
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && ($_POST['photo_desc'] !="")) {
$file_dir = "images/";
for($i=0; $i<3;$i++){
//test if upload was complete
if(isset($_FILES['upfile']['error'][$i]) && $_FILES['upfile']['error'][$i]==0 && $_FILES['upfile']['name'][$i]!= ""){
$newfile[$i] = $file_dir.$_FILES['upfile']['name'][$i];
move_uploaded_file($_FILES['upfile']['tmp_name'][$i], $newfile[$i]);
$name = substr($_FILES['upfile']['name'][$i],-4);
$j++;
if (isset($j)&&$j>0) $message = "Your file(s) has been uploaded.<br><br>Choose 3 files to upload...<br>";
}else{
$newfile[$i] = 'File not uploaded';
}
}
$insertSQL = sprintf("
INSERT
INTO
photo_table
(
photo_id,
photo_client_id,
photo_category,
photo_name,
photo_keyword,
photo_desc,
photo_thumb_name,
photo_4x6_name,
photo_6x9_name
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['photo_id'], "int"),
GetSQLValueString($_POST['photo_client_id'], "int"),
GetSQLValueString($_POST['photo_category'], "int"),
GetSQLValueString($_POST['photo_name'], "text"),
GetSQLValueString($_POST['photo_keyword'], "text"),
GetSQLValueString($_POST['photo_desc'], "text"),
GetSQLValueString($name[0], "text"),
GetSQLValueString($name[1], "text"),
GetSQLValueString($name[2], "text")
);
mysql_select_db($database_database, $database);
mysql_query($insertSQL, $database) or die(mysql_error());
This is what it does. example. if image name is "imgname.jpg" and the database fields are image1,image2,image3.
image1 image2 image3
. j p
should be:
image1 image2 image3
imgname imgname imgname
instead of giving me the name of each image with out the ".jpg"
Any help is appreciated.
thanks in advance..
here is my code
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && ($_POST['photo_desc'] !="")) {
$file_dir = "images/";
for($i=0; $i<3;$i++){
//test if upload was complete
if(isset($_FILES['upfile']['error'][$i]) && $_FILES['upfile']['error'][$i]==0 && $_FILES['upfile']['name'][$i]!= ""){
$newfile[$i] = $file_dir.$_FILES['upfile']['name'][$i];
move_uploaded_file($_FILES['upfile']['tmp_name'][$i], $newfile[$i]);
$name = substr($_FILES['upfile']['name'][$i],-4);
$j++;
if (isset($j)&&$j>0) $message = "Your file(s) has been uploaded.<br><br>Choose 3 files to upload...<br>";
}else{
$newfile[$i] = 'File not uploaded';
}
}
$insertSQL = sprintf("
INSERT
INTO
photo_table
(
photo_id,
photo_client_id,
photo_category,
photo_name,
photo_keyword,
photo_desc,
photo_thumb_name,
photo_4x6_name,
photo_6x9_name
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['photo_id'], "int"),
GetSQLValueString($_POST['photo_client_id'], "int"),
GetSQLValueString($_POST['photo_category'], "int"),
GetSQLValueString($_POST['photo_name'], "text"),
GetSQLValueString($_POST['photo_keyword'], "text"),
GetSQLValueString($_POST['photo_desc'], "text"),
GetSQLValueString($name[0], "text"),
GetSQLValueString($name[1], "text"),
GetSQLValueString($name[2], "text")
);
mysql_select_db($database_database, $database);
mysql_query($insertSQL, $database) or die(mysql_error());