Jump to content

Recommended Posts

Hi Guys,

 

Im not a PHP developer by far i mainly work with front end desgin but ive been editing some code on a website left by the previous web developer.

What i have is a news editor in the admin section of a site which has

 

Image Uploader - upload an image which works fine

title - text input box which works fine

image - javascript wysiwyg editor which doesnt work very well

news - javascript wysiwyg editor which works fine

ref - text input box which works fine.

 

So what i would like to do is in the image part i want to display all the images in the uploaded image folder and then have checkboxes next to the images so that the user can select an image to use.

 

Then when they have filled in all the other fields like Title, News, Ref etc for the image to also be added to the news item.

 

My Code so far

 

<?php require_once('../Connections/keylekkerland.php'); ?>
<?
//print_r($_POST);

if($_POST["action"] == "Upload Image")
{
unset($imagename);

if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;

if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";


$imagename = basename($_FILES['image_file']['name']);
//echo $imagename;

if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";

if(empty($error))
{
$newimage = "newsimages/" . $imagename;
//echo $newimage;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}

}

?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);

  $logoutGoTo = "../index.html";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['delete'])) && ($_GET['delete'] != "")) {
  $deleteSQL = sprintf("DELETE FROM News WHERE id=%s",
                       GetSQLValueString($_GET['delete'], "text"));

  mysql_select_db($database, $keylekkerland);
  $Result1 = mysql_query($deleteSQL, $keylekkerland) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO News (id, title, `image`, `news`, `ref`) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['hiddenField'], "date"),
                       GetSQLValueString($_POST['Title'], "text"),
                       GetSQLValueString($_POST['image'], "text"),
				   GetSQLValueString($_POST['news'], "text"),
                       GetSQLValueString($_POST['Reference'], "text"));

  mysql_select_db($database, $keylekkerland);
  $Result1 = mysql_query($insertSQL, $keylekkerland) or die(mysql_error());
}

mysql_select_db($database, $keylekkerland);
$query_News = "SELECT * FROM News";
$News = mysql_query($query_News, $keylekkerland) or die(mysql_error());
$row_News = mysql_fetch_assoc($News);
$totalRows_News = mysql_num_rows($News);
?><!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Key Lekkerland | Login</title>
<link rel="shortcut icon" href="favicon.ico" >
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script src="../css_browser_selector.js" type="text/javascript"></script>
<script src="../Scripts/AC_RunActiveContent.js" type="text/javascript"></script>

<style type="text/css">
<!--
.style3 {
font-size: 18px;
font-weight: bold;
color: #FF0000;
}
.style4 {font-family: Tahoma}
.style5 {font-size: 16px}
.style6 {
font-family: Tahoma;
font-size: 14px;
color: #FF0000;
font-weight: bold;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<script language="JavaScript" type="text/javascript" src="wysiwyg.js">
</script>
</head>

<body onload="MM_preloadImages('../images/LOGOUTOVER.gif','../images/customer-login-over.gif','../images/not-yet-registered-over.gif')">
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#FFFFFF"><img src="../images/logo.gif" alt="lekkerland-logo" width="194" height="110" />
      <script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','250','height','110','src','../flash/slogan','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','../flash/slogan' ); //end AC code
      </script>
      <noscript>
      <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="250" height="110">
        <param name="movie" value="../flash/slogan.swf" />
        <param name="quality" value="high" />
        <embed src="../flash/slogan.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="250" height="110"></embed>
      </object>
      </noscript>
    </td>
  </tr>
</table>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#ED1B2F">
  <tr>
    <td height="60"> </td>
  </tr>
</table>
<table width="1000" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
  <tr>
    <td width="192" align="left" valign="top" bgcolor="#e0e1e3"><div id="left">
    	<ul>
        	<li><a class="menu" href="../index.html">Home</a></li>
            <li><a class="menu" href="../news.php">News</a></li>
          <li><a class="menu" href="../wholesale-members.html">Wholesale Members</a></li>
            <li><a class="menu" href="../contact-us.html">Contact us</a></li>
        </ul>
    
        <div align="center"> <br />
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center" valign="top"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','179','height','329','title','Deals','src','../flash/lekkerland-deals','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','../flash/lekkerland-deals' ); //end AC code
          </script>
                  <noscript>
                    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="179" height="329" title="Deals">
                    <param name="movie" value="../flash/lekkerland-deals.swf" />
                    <param name="quality" value="high" />
                    <embed src="../flash/lekkerland-deals.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="179" height="329"></embed>
                  </object>
                  </noscript></td>
            </tr>
          </table>
      </div>
    </div></td>
    <td align="left" valign="top" bgcolor="#FFFFFF"><div id="mid"><table width="95%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="10" height="35"> </td>
    <td align="left" valign="bottom"><a href="<?php echo $logoutAction ?>" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('LOGOUT','','../images/LOGOUTOVER.gif',1)"><img src="../images/LOGOUT.gif" alt="Logout" name="LOGOUT" width="61" height="25" border="0" id="LOGOUT" /></a></td>
  </tr>
</table>

<table width="95%" border="0" cellspacing="0" cellpadding="6">
  <tr>
    <td><form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>">
<p>If you wish to use an image in your news item you can upload it here using the image uploader.</p>
<p>
  <input type="file" name="image_file" size="20">
</p>
<p><input type="submit" value="Upload Image" name="action"></p>
</form>

<?
if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>\n";
}
}
?></td>
  </tr>
</table>
<span class="style6">*Please make sure to fill in all Sections to add your news article.</span>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="95%" border="0" cellspacing="4" cellpadding="0">
    <tr>
      <td> </td>
      <td><input name="hiddenField" type="hidden" id="hiddenField" /></td>
    </tr>
    <tr>
      <td align="left" valign="top">Title:</td>
      <td><input name="Title" type="text" id="Title" size="50" /></td>
    </tr>
    <tr>
      <td align="left" valign="top">Image:</td>
      <td>Please note if you have uploaded a new image your image URL will be<br />
        <span class="style5">http://www.tktest.co.uk/lekkerland/admin/newsimages/yourimagename</span><br />
        And select Layout Align Left before inserting your image.<br />
      <textarea name="image" id="image" cols="30" rows="2"></textarea></td>
    </tr>
    <tr>
      <td align="left" valign="top">News:</td>
      <td><textarea name="news" id="news" cols="30" rows="2"></textarea></td>
    </tr>
    <tr>
      <td align="left" valign="top">Reference:</td>
      <td><input name="Reference" type="text" id="Reference" size="50" /></td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" name="add" id="add" value="Add News" /> 
        <span class="style4">* Remember only the top 4 News in the list are shown within the website...</span></td>
    </tr>
  </table>
  <br />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<script language="javascript1.2">
  generate_wysiwyg('image');
  generate_wysiwyg('news');
</script> </div>
</div>
</div></td>
    <td width="212" align="right" valign="top" bgcolor="#e0e1e3"><table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="center" valign="top"><a href="http://web6.enable.com/keylekkerland/Login.aspx" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Customer Login','','../images/customer-login-over.gif',1)"><img src="../images/customer-login.gif" alt="Customer Login" name="Customer Login" border="0" id="Customer Login" /></a></td>
      </tr>
      <tr>
        <td align="center" valign="top"><a href="http://web6.enable.com/KeyLekkerland/Enquiry.aspx?PageID=136843&enqtype=Retail" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Not yet Registered?','','../images/not-yet-registered-over.gif',1)"><img src="../images/not-yet-registered.gif" alt="Not yet Registered?" name="Not yet Registered?" border="0" id="Not yet Registered?" /></a></td>
      </tr>
    </table></td>
  </tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td height="1"></td>
  </tr>
</table>
<div id="footer"><br />
Copyright © Key Lekkerland 2008 - <a href="http://web6.enable.com/KeyLekkerland/Terms.aspx" class="botlinks">Terms and Conditions</a> - <a href="http://web6.enable.com/KeyLekkerland/Privacy.aspx" class="botlinks">Privacy</a> - <a href="http://www.tktest.co.uk/lekkerland/admin/login.php" class="botlinks">News Admin</a></div>
</div> 
<!--end wrap-->
<table width="100%" border="0" cellspacing="2" cellpadding="0">
  <tr>
    <td bgcolor="#000000"><span class="style3">Timestamp</span></td>
    <td bgcolor="#000000"><span class="style3">Title</span></td>
    <td bgcolor="#000000"><span class="style3">Image </span></td>
    <td bgcolor="#000000"><span class="style3">News</span></td>
    <td bgcolor="#000000"><span class="style3">Reference</span></td>
    <td bgcolor="#000000"> </td>
  </tr>
  <?php do { ?>
    <tr>
      <td bgcolor="#E6F9FF"><?php echo $row_News['id']; ?></td>
      <td bgcolor="#E6F9FF"><?php echo $row_News['title']; ?></td>
      <td bgcolor="#E6F9FF"><?php echo $row_News['image']; ?></td>
      <td bgcolor="#E6F9FF"><?php echo $row_News['news']; ?></td>
      <td bgcolor="#E6F9FF"><?php echo $row_News['ref']; ?></td>
      <td bgcolor="#E6F9FF"><a href="edit.php?RecordID=<?php echo $row_News['id']; ?>">Edit</a> <a href="index.php?delete=<?php echo $row_News['id']; ?>">| Delete</a></td>
    </tr>
    <?php } while ($row_News = mysql_fetch_assoc($News)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($News);
?>

 

 

Please can someone help??

 

Link to comment
https://forums.phpfreaks.com/topic/99166-displaying-images-with-php/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.