I have created the code that allows me to load a picture in a folder on the server.I would have to insert the name of the picture loaded inside the db. the voice in table where it goes loaded this name is 'release_image'.
the code that use is this but does not work
file submit.php
include("header.php");
include '../mainfile.php';
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
//aggiunta
$release_image = isset($_POST['upload_file']) ? $_POST['upload_file'] : array();
//Imposto i tipi di file autorizzati
$allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png');
// Massimo peso
$maxfilesize = 100000;
//larghezza e lunghezza
$maxfilewidth = 150;
$maxfileheight = 150;
//Richiamo la classe uploader e gli passo i parametri inizializzati
//Nota: il primo parametro è il nome della cartella dove verrà salvato il file. In questo caso la cartella è nella stessa dierctory di questo file
$uploader = new XoopsMediaUploader(XOOPS_ROOT_PATH.'/uploads/copertine', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
//imposto un prefisso per l'immagine
$uploader->setPrefix('img');
//Upload del file
if ($uploader->fetchMedia($release_image[0])) {
if (!$uploader->upload()) {
//Errori?
echo $uploader->getErrors();
} else {
//Tutto OK!
echo 'File caricato con successo!';
echo 'File salvato come: ' . $uploader->getSavedFileName() . '';
echo 'Path completa: ' . $uploader->getSavedDestination(). '';
echo 'Nome del file: ' . $uploader->getMediaName(). '';
echo 'Tipo di file: ' . $uploader->getMediaType(). '';
echo 'Peso: ' . $uploader->getMediaSize(). '';
echo 'Nome file temporaneo: ' . $uploader->getMediaTmpName(). '';
echo 'Directory dove è stato salvato: ' . $uploader->getSavedDestination(). '';}
} else {
echo $uploader->getErrors();
}
$myts =& MyTextSanitizer::getInstance();
$xoopsOption['show_rblock'] =0;
include(XOOPS_ROOT_PATH."/header.php");
//Global $xoopsUser, $xoopsConfig;
$op = "submit";
if (isset($HTTP_GET_VARS)) {
foreach ($HTTP_GET_VARS as $k => $v) {
$$k = $v;
}
}
if (isset($HTTP_POST_VARS)) {
foreach ($HTTP_POST_VARS as $k => $v) {
$$k = $v;
}
}
if (!empty($contents_preview)) {
$myts =& MyTextSanitizer::getInstance();
//OpenTable();
//echo ""._XD_CATEGORY.": ".$category_id;
$html = empty($review_nohtml) ? 1 : 0;
$smiley = empty($review_nosmiley) ? 1 : 0;
$xcode = empty($review_noxcode) ? 1 : 0;
$p_title = $myts->makeTboxData4Preview($review_title);
$p_item = $myts->makeTboxData4Preview($review_item);
$p_label = $myts->makeTboxData4Preview($review_label);
$p_release = $myts->makeTboxData4Preview($release_date);
$p_format = $myts->makeTboxData4Preview($release_format);
$p_contents = $myts->makeTareaData4Preview($review_contents, $html, $smiley, $xcode);
$p_image = $myts->makeTboxData4PreviewInForm($release_image);
echo"<table border='0' cellpadding='3' cellspacing='0' valign='top' width='100%'><tr><td class='bg2'>
<table width='100%' border='0' cellpadding='4' cellspacing='1'>
<tr class='bg3' align='center'><td align='left'>$p_title</td></tr>
<tr class='bg3' align='center'><td align='left'>$p_item</td></tr>
<tr class='bg3' align='center'><td align='left'>$p_label</td></tr>
<tr class='bg3' align='center'><td align='left'>$p_release</td></tr>
<tr class='bg3' align='center'><td align='left'>$p_format</td></tr>
<tr class='bg3' align='center'><td align='left'>$p_image</td></tr>
<tr class='bg1'><td>$p_contents</td></tr></table></td></tr></table><br />";
$review_title = $myts->makeTboxData4PreviewInForm($review_title);
$review_item = $myts->makeTboxData4PreviewInForm($review_item);
$review_label = $myts->makeTboxData4PreviewInForm($review_label);
$release_date = $myts->makeTboxData4PreviewInForm($release_date);
$release_format = $myts->makeTboxData4PreviewInForm($release_format);
$release_image = $myts->makeTboxData4PreviewInForm($release_image);
$review_contents = $myts->makeTareaData4PreviewInForm($review_contents);
include("contentsform.php");
//CloseTable();
include (XOOPS_ROOT_PATH."/footer.php");
exit();
}
if ($op == "submit") {
OpenTable();
$myts =& MyTextSanitizer::getInstance();
//echo "<h4 style='text-align:left;'>"._XD_ADDCONTENTS."</h4>";
$review_title = "";
$review_contents = "";
$review_item ="";
$review_label ="";
$release_date ="";
$release_format ="";
$release_image = "";
$review_visible = 0;
$review_nohtml = 0;
$review_nosmiley = 0;
$review_noxcode = 0;
$review_id = 0;
$category_id = 0;
$op = "addcontentsgo";
include("contentsform.php");
CloseTable();
include (XOOPS_ROOT_PATH."/footer.php");
exit();
}
if ($op == "addcontentsgo") {
OpenTable();
$myts =& MyTextSanitizer::getInstance();
$title = $myts->makeTboxData4Save($review_title);
$item = $myts->makeTboxData4Save($review_item);
$label = $myts->makeTboxData4Save($review_label);
$release = $myts->makeTboxData4Save($release_date);
$format = $myts->makeTboxData4Save($release_format);
$image = $myts->makeTboxData4Save($release_image);
$contents = $myts->makeTareaData4Save($review_contents);
/*
$result = $xoopsDB->query("SELECT category_id, category_title FROM ".$xoopsDB->prefix("lykos_reviews_categories")."");
while(list($cat,$cat_title) = $xoopsDB->fetchRow($result)) {
if($category_id==$cat_title) {
$category_id=$cat;
}
}
*/
$category_id = $myts->makeTareaData4Save($category_id);
if($xoopsUser->uid()) {
$submitter = $xoopsUser->uid();
} else {
$submitter = 0;
}
$newid = $xoopsDB->genId($xoopsDB->prefix("lykos_reviews_contents")."_review_id_seq");
$sql = "INSERT INTO ".$xoopsDB->prefix("lykos_reviews_contents")." (review_id, category_id, review_title, review_item, review_label, release_date, release_format, release_image, review_contents, review_uid, review_time, review_visible, review_nohtml, review_nosmiley, review_noxcode) VALUES (".$newid.", ".$category_id.", '".$title."', '".$item."', '".$label."', '".$release."', '".$format."', '".$image."', '".$contents."', '".$submitter."',".time().", ".intval($review_visible).", ".intval($review_nohtml).", ".intval($review_nosmiley).", ".intval($review_noxcode).")";
if (!$xoopsDB->query($sql)) {
echo "Impossibile aggiungere contenuti";
CloseTable();
include (XOOPS_ROOT_PATH."/footer.php");
} else {
redirect_header("index.php",1,_XD_DBSUCCESS);
}
exit();
}
?>
the file with the form:contentsform.php
echo "<form action='submit.php' method='post' enctype='multipart/form-data' />";
echo "<table border='0' cellpadding='0' cellspacing='0' valign='top' width='100%'><tr><td class='bg2'>";
echo "<table width='100%' border='0' cellpadding='4' cellspacing='1'>";
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_QUESTION." </td><td class='bg1'><input type='text' name='review_title' value='$review_title' size='31' maxlength='255' /></td></tr>";
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_CATEGORY."</td><td class='bg1'><select name="category_id">";
$a=0;
$result = $xoopsDB->query("SELECT category_id, category_title FROM ".$xoopsDB->prefix("lykos_reviews_categories")."");
while(list($cat_id,$cat_title) = $xoopsDB->fetchRow($result)) {
if($cat_id==$category_id) {
echo "<option value="$cat_id" selected>$cat_title</option>n";
$a=1;
}
else {
echo "<option value="$cat_id">$cat_title</option>n";
}
}
if($a==1) {
echo"<option selected>[Choose Category]";
}
echo "</select></td></tr>";
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_ITEM." </td><td class='bg1'><input type='text' name='review_item' value='$review_item' size='31' maxlength='255' /></td></tr>";
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_LABEL." </td><td class='bg1'><input type='text' name='review_label' value='$review_label' size='31' maxlength='255' /></td></tr>";
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_RELEASE." </td><td class='bg1'><input type='text' name='release_date' value='$release_date' size='31' maxlength='255' /></td></tr>";
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_FORMAT." </td><td class='bg1'><input type='text' name='release_format' value='$release_format' size='31' maxlength='255' /></td></tr>";
echo "<tr><td nowrap='nowrap' class='bg3'><input type='hidden' name='MAX_FILE_SIZE' value='100000' />";
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_IMAGE."</td><td class='bg1'><input type='file' name='image_file' value='$release_image' size='31' maxlength='255' /><br /></td></tr>";
echo "<tr><td nowrap='nowrap' class='bg3'><input type='hidden' name='upload_file[]' id='upload_file[]' value='image_file' />";
//oldfield
echo "<input type='hidden' name='release_image' value='".$release_image."' size='31' maxlength='255' /></td></tr>";
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_AMAZN." </td><td class='bg1'><input type='text' name='release_amazon' value='".$review_amazon."' size='31' maxlength='255' /></td></tr>";
$checked = ($review_visible == 1) ? " checked='checked'" : "";
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_DISPLAY." </td><td class='bg1'><input type='checkbox' name='review_visible' value='1'$checked /></td></tr>";
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_ANSWER." </td><td class='bg1'>";
include_once(XOOPS_ROOT_PATH."/include/xoopscodes.php");
xoopsCodeTarea("review_contents", 39, 20);
xoopsSmilies("review_contents");
$checked = ($review_nohtml == 1) ? " checked='checked'" : "";
echo "<br /><input type='checkbox' name='review_nohtml' value='1'$checked />"._XD_NOHTML."<br />";
$checked = ($review_nosmiley == 1) ? " checked='checked'" : "";
echo "<input type='checkbox' name='review_nosmiley' value='1'$checked />"._XD_NOSMILEY."<br />";
$checked = ($review_noxcode == 1) ? " checked='checked'" : "";
echo "<input type='checkbox' name='review_noxcode' value='1'$checked />"._XD_NOXCODE."</td></tr>";
echo "<tr><td nowrap='nowrap' class='bg3'> </td><td class='bg1'><input type='hidden' name='review_id' value='".$review_id."' /><input type='hidden' name='op' value='$op' /><input type='submit' name='contents_preview' value='"._PREVIEW."' /> <input type='submit' name='contents_submit' value='"._SUBMIT."' /></td></tr>";
echo "</table></td></tr></table></form>";
include("image_uploader.php");
?>
all the contents of the form come send to db except the name of the picture. Opening the sql file of the database to the place of the name I obtain only an empty space: "" in place of “picture.jpg”. where is the error? Thanks