I have a form that inputs data into a mysql database and inserts an image file into a specified directory. I need my formhandler to also rename the image file to the row id of the data.
How can I do this???? Here is my formhandler
<html>
<head>
<title>Inserting Data into Article Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
/ This page processes "article_form.htm". /
$Host = "localhost";
$User = "username";
$Password = "password";
$DBName = "dbname";
$TableName = "tbname";
//Trim the incoming data.
$Array["last_name"] = trim ($Array["last_name"]);
$Array["first_name"] = trim ($Array["first_name"]);
$Array["email_address"] = trim ($Array["email_address"]);
$Array["vehicle_category"] = trim ($Array["vehicle_category"]);
$Array["vehicle_year"] = trim ($Array["vehicle_year"]);
$Array["vehicle_make"] = trim ($Array["vehicle_make"]);
$Array["vehicle_model"] = trim ($Array["vehicle_model"]);
$Array["vehicle_mileage"] = trim ($Array["vehicle_mileage"]);
$Array["years_owned"] = trim ($Array["years_owned"]);
$Array["city"] = trim ($Array["city"]);
$Array["state"] = trim ($Array["state"]);
$Array["fav_places"] = trim ($Array["fav_places"]);
$Array["where_drive"] = trim ($Array["where_drive"]);
$Array["fastest_driven"] = trim ($Array["fastest_driven"]);
$Array["performance_upgrades"] = trim ($Array["performance_upgrades"]);
$Array["audio_upgrades"] = trim ($Array["audio_upgrades"]);
$Array["wheels"] = trim ($Array["wheels"]);
$Array["finished"] = trim ($Array["finished"]);
$Array["what_else"] = trim ($Array["what_else"]);
$Array["do_work"] = trim ($Array["do_work"]);
$Array["what_work"] = trim ($Array["what_work"]);
$Array["unique"] = trim ($Array["unique"]);
$Array["performance_brands"] = trim ($Array["performance_brands"]);
$Array["audio_brands"] = trim ($Array["audio_brands"]);
$Link = mysql_connect ($Host, $User, $Password);
$Query = "INSERT into $TableName values
('0', '$Array[first_name]', '$Array[last_name]', '$Array[email_address]',
'$Array[vehicle_category]', '$Array[vehicle_year]',
'$Array[vehicle_make]', '$Array[vehicle_model]',
'$Array[vehicle_mileage]', '$Array[years_owned]',
'$Array[city]', '$Array[state]', '$Array[fav_places]',
'$Array[where_drive]', '$Array[fastest_driven]',
'$Array[performance_upgrades]', '$Array[audio_upgrades]',
'$Array[wheels]', '$Array[finished]', '$Array[what_else]',
'$Array[do_work]', '$Array[what_work]', '$Array[unique]',
'$Array[performance_brands]', '$Array[audio_brands]')";
print ("The query is:<BR>$Query<P>\n");
if (mysql_db_query($DBName,$Query,$Link)){
print ("The query was successfully executed!<BR>\n");
} else {
print ("The query could not be executed!<BR>\n");
}
//change these values to suit your site
$ftp_user_name='username';
$ftp_user_pass='password';
$ftp_server='ftp.enduroautomotive.com';
$ftp_dir='Magazine/';
//$web_location is needed for the file_exists function, the directories used by FTP
//are not visible to it will will always return not found.
$web_dir='/home/enduroauto/www/www/Magazine/';
$web_location=$web_dir.$row['id'].".jpg";
//build a fully qualified (FTP) path name where the file will reside
$destination_file=$ftp_dir.$row['id'].".jpg";
// connect, login, and transfer the file
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$mode= ftp_pasv($conn_id, 1);
$upload = ftp_put($conn_id, $destination_file, $imagefile, FTP_BINARY);
//use ftp_site to change mode of the file
//this will allow it be visible by the world,
$ch=ftp_site($conn_id,"chmod 777 ".$destination_file);
// close the FTP stream
ftp_close($conn_id);
//verify file was written
if (file_exists($web_location))
{
echo "file was uploaded as $web_location";
}
else
{
echo "Could not create $web_location";
}
//end if
mysql_close($Link);
?>
</body>
</html>