Jump to content

emediastudios

Members
  • Posts

    418
  • Joined

  • Last visited

Posts posted by emediastudios

  1. I changed the code you pm me to this

     

    <?PHP 
    
    $folder = "../images/"; 
    $handle = opendir($folder); 
    
    # Making an array containing the files in the current directory: 
    while (false !== ($file = readdir($handle)))
    {
        if ($file != '.' && $file != '..')
           $files[] = $file; 
    } 
    closedir($handle); 
    
    #echo the files 
    foreach ($files as $file) { 
        echo "-<a href=$folder$file><label title=file>$file</a></label>";
    echo "-<a href=filedelete.php?file=$file>Delete</a><br />";
        echo '<img src="$file" alt="image" width="150" />';
    } 
    ?>
    

    i tried to get a thumnail to display but it doesnt

  2. Well, firstly, the parameter you pass is called file - with a small f. The file you try to unlink is called $File with a capital F. Also, did you retrieve that variable from the $_GET array?

     

    Try:

     

    <?php
    unlink($_GET['file']);
    ?>
    

     

    I did a s you recommended and get the following error

    Warning: unlink(Object) [function.unlink]: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\images\delete.php on line 2

  3. Thanks for trying man, looks like a lot of work.

    The code here below lists all my files.

    <?php
    $folder = "../images/"; 
    $handle = opendir($folder); 
    
    # Making an array containing the files in the current directory: 
    while (false !== ($file = readdir($handle)))
    {
        if ($file != '.' && $file != '..')
           $files[] = $file; 
    } 
    closedir($handle); 
    
    #echo the files 
    foreach ($files as $file) { 
        echo "<br />$file<a href=delete.php?file=$file> 'Delete'</a>"; 
    } 
    ?>
    

     

    I will make some changes later in its appearance but the code does its thing.

     

    the code i need to sort out is the delete.php

    i'm a newbie to php but am getting a little drift of things.

    i tried this code but to no avail

     

    delete.php

    <?php
    {unlink($File);}
    ?> 
    
    

  4. I used the code off this site and replaced the one that im using above.

     

    <?php
    $folder = "../images/"; 
    $handle = opendir($folder); 
    
    # Making an array containing the files in the current directory: 
    while (false !== ($file = readdir($handle)))
    {
        if ($file != '.' && $file != '..')
           $files[] = $file; 
    } 
    closedir($handle); 
    
    #echo the files 
    foreach ($files as $file) { 
        echo "<br />$file<a href=delete.php?$file=$file> 'Delete'</a>"; 
    } 
    ?>

    This shows all the files in my folder.

     

    Then i changed the delete.php file with this code only

     

    <?php
    {unlink($File);}
    ?> 
    
    

     

    and i get this error

     

    Warning: unlink() [function.unlink]: Permission denied in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\delete.php on line 2

  5. I found a simpler code that does the same thing.

    Can i use this code with some extra coding to show the selected image and then option to delete on submit?

    It seems that there is a demand for this code.

    <?php
    echo "<select name=\"file\">\n";
    foreach (new DirectoryIterator('.') as $file) {
       // if the file is not this file, and does not start with a '.' or '..',
       // then store it for later display
       if ( (!$file->isDot()) && ($file->getFilename() != basename($_SERVER['PHP_SELF'])) ) {
          echo "<option>";
          // if the element is a directory add to the file name "(Dir)"
          echo ($file->isDir()) ? "(Dir) ".$file->getFilename() : $file->getFilename();
          echo "</option>\n";
       }
    }
    echo "</select>\n";
    ?>

  6. I wanted to create a file that lists all the files in a directory, show a thumbnail of each and give an option to delete.

    Is this hard to do?

    I have this code i found on the web

    <?php
    // open the current directory
    $dhandle = opendir('.');
    // define an array to hold the files
    $files = array();
    
    if ($dhandle) {
       // loop through all of the files
       while (false !== ($fname = readdir($dhandle))) {
          // if the file is not this file, and does not start with a '.' or '..',
          // then store it for later display
          if (($fname != '.') && ($fname != '..') &&
              ($fname != basename($_SERVER['PHP_SELF']))) {
              // store the filename
              $files[] = (is_dir( "./$fname" )) ? "(Dir) {$fname}" : $fname;
          }
       }
       // close the directory
       closedir($dhandle);
    }
    
    echo "<select name=\"file\">\n";
    // Now loop through the files, echoing out a new select option for each one
    foreach( $files as $fname )
    {
       echo "<option>{$fname}</option>\n";
    }
    echo "</select>\n";
    ?>

    It creates a nice list, but to get the files to display on click and an option to delete is over my head, any ideas or does someone have a code or link that could help mm.

    Thanks

  7. I got it to work ;D

    But this code looks wrong there are duplicate codes

     

    <?php
    if ((isset($_POST['id'])) && ($_POST['id'] != "")) {
      $deleteSQL = sprintf("DELETE FROM employees WHERE id=%s",
                           GetSQLValueString($_POST['id'], "int"));
    
      mysql_select_db($database_gcproperty, $gcproperty);
      $Result1 = mysql_query($deleteSQL, $gcproperty) or die(mysql_error());
    
      $deleteGoTo = "property_deleted.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
        $deleteGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $deleteGoTo));
    }
    
    if ((isset($_POST['id'])) && ($_POST['id'] != "")) {
      $deleteSQL = sprintf("DELETE FROM employees WHERE id=%s",
                           GetSQLValueString($_POST['id'], "int"));
    
      mysql_select_db($database_gcproperty, $gcproperty);
      $Result1 = mysql_query($deleteSQL, $gcproperty) or die(mysql_error());
    
    
    $deleteGoTo = "property_deleted.php";
       if (isset($_SERVER['QUERY_STRING'])) {
        $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
        $deleteGoTo .= $_SERVER['QUERY_STRING'];
    
    $myFile = array();
    for($i=1;$i<=9;$i++) {
    $myFile[$i] = "../images/" . $_POST['photo' . $i];
         if (!empty($_POST['photo'.$i]))
              unlink($myFile[$i]);
    }
    
      
    }
      
      header("Location: $deleteGoTo");
    
    }
    
    mysql_select_db($database_gcproperty, $gcproperty);
    $query_Recordset1 = "SELECT * FROM employees ORDER BY id ASC";
    $Recordset1 = mysql_query($query_Recordset1, $gcproperty) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?>

    I deleted the duplicated code but i get errors.

  8. I have records in my database that all have a id number that is unique ,

    But if i have the same name on a record and i delete the record from a dreamweaver generated code it deletes all records of the same name. I want to filter my deletion by id so that if i had 10 properties with the same name it would only delete the selected record?

    Does this make sense.

     

    Heres the code i use in my file

    <?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;
    }
    }
    
    if ((isset($_POST['id'])) && ($_POST['id'] != "")) {
      $deleteSQL = sprintf("DELETE FROM employees WHERE id=%s",
                           GetSQLValueString($_POST['id'], "int"));
    
      mysql_select_db($database_gcproperty, $gcproperty);
      $Result1 = mysql_query($deleteSQL, $gcproperty) or die(mysql_error());
    
      $deleteGoTo = "property_deleted.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
        $deleteGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $deleteGoTo));
    }
    
    if ((isset($_POST['name'])) && ($_POST['name'] != "")) {
      $deleteSQL = sprintf("DELETE FROM employees WHERE name=%s",
                           GetSQLValueString($_POST['name'], "text"));
    
      mysql_select_db($database_gcproperty, $gcproperty);
      $Result1 = mysql_query($deleteSQL, $gcproperty) or die(mysql_error());
    
    
    $deleteGoTo = "property_deleted.php";
       if (isset($_SERVER['QUERY_STRING'])) {
        $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
        $deleteGoTo .= $_SERVER['QUERY_STRING'];
    
    $myFile = array();
    for($i=1;$i<=9;$i++) {
    $myFile[$i] = "../images/" . $_POST['photo' . $i];
         if (!empty($_POST['photo'.$i]))
              unlink($myFile[$i]);
    }
    
      
    }
      
      header("Location: $deleteGoTo");
    
    }
    
    mysql_select_db($database_gcproperty, $gcproperty);
    $query_Recordset1 = "SELECT * FROM employees ORDER BY id ASC";
    $Recordset1 = mysql_query($query_Recordset1, $gcproperty) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?>

  9. I have a field in my table called rank, when a property is added my client chooses from a list a number from one to 10.

    and that number is inserted in the record, i thought this would be the best way to display the properties in order of rank.

    I am making this site in dreamweaver and am unsure on how to filter my recordset to display the results by rank, 1 being the best.

    Sorry for asking a stupid question, but am ;) learning

  10. I changed it all so that there is no reference to (id) anywhere in my code.

    And changed my insert statement to

     

    mysql_query("INSERT INTO `employees` VALUES ('id','$name', '$rank', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')");

     

    And it does nothing.

    It says property added successfully but doesnt add the record ??? i removed the $ from the start of id.

    What am i doing wrong?

    Is my id field correctly structured, should it have a defult value? and should it be asigned as a primary key?

     

    Thanks in advanced

     

     

  11. ok, i get a drift of what u are saying, i deleted the input field and the get from form $id

     

    But in the insert statement it is formatted as

     

    <?php
    //Writes the information to the database
          mysql_query("INSERT INTO `employees` VALUES ('$id','$name', '$rank', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')");
    
    // ?>

    Should it be a different insert statement as $id now no longer exists in my files?

    Should it read

     

     

      mysql_query("INSERT INTO `employees` VALUES ('id','$name', '$rank', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')");

     

    //

     

     

  12. So do i still need a hidden (id) field?

    and do i need the id in my proccess file?

     

    <?php
    //This gets all the other information from the form 
    $id=$_POST['id']; // do i need this?/////////////////////////////////////////////////////////////
    $name=$_POST['name']; 
    $rank=$_POST['rank']; 
    $suburb=$_POST['suburb']; 
    $price=$_POST['price']; 
    $content=$_POST['content']; 
    $content2=$_POST['content2']; 
    $agentmobile=$_POST['agentmobile']; 
    $agentemail=$_POST['agentemail']; 
    $uploadFile0=($_FILES['uploadFile0']['name']); 
    $uploadFile1=($_FILES['uploadFile1']['name']);
    $uploadFile2=($_FILES['uploadFile2']['name']); 
    $uploadFile3=($_FILES['uploadFile3']['name']);
    $uploadFile4=($_FILES['uploadFile4']['name']);
    $uploadFile5=($_FILES['uploadFile5']['name']);
    $uploadFile6=($_FILES['uploadFile6']['name']);
    $uploadFile7=($_FILES['uploadFile7']['name']);
    $uploadFile8=($_FILES['uploadFile8']['name']);
    ?>

     

    Do i just do the code for the auto increment in this part of my code?

     

    //Writes the information to the database

     

     

    mysql_query("INSERT INTO `employees` VALUES ('$id','$name', '$rank', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')");

     

    //

     

    Sorry im stil learning, this is my first php/mysql project, thanks for your help ;)

     

    Is my id field setup correctly?

    Should it be a "primary key"

    It has a key beside it in dreamweaver and says that it is required?

     

  13. Hi everyone.

    I have made a code that adds properties to a website, it uploads images, and inserts all the data(property details and image paths) to my database.

    It works well except for one thing, i cant get the auto_increment to work.

    I had the auto_increment field as "hidden" in my add_property.php file and it wouldnt work.

    If i had the field not hidden and added a number it works, and if that number is the same as as a other property id it replaces it.

    Do i need that field in my file at all? and should i even have it in my insert statement?

    Shouldnt that insert automatically my id in an auto increment.

    I am unable also to set a default value in my id field.

    here is my table structure.

     

    # Table structure for table `employees`

    #

     

    DROP TABLE IF EXISTS `employees`;

    CREATE TABLE `employees` (

      `id` int(4) NOT NULL auto_increment,

      `name` varchar(100) default NULL,

      `rank` int(10) default NULL,

      `suburb` varchar(100) default NULL,

      `price` varchar(100) default NULL,

      `content` text,

      `content2` text,

      `agentmobile` varchar(100) default NULL,

      `agentemail` varchar(100) default NULL,

      `photo1` varchar(100) default NULL,

      `photo2` varchar(100) default NULL,

      `photo3` varchar(100) default NULL,

      `photo4` varchar(100) default NULL,

      `photo5` varchar(100) default NULL,

      `photo6` varchar(100) default NULL,

      `photo7` varchar(100) default NULL,

      `photo8` varchar(100) default NULL,

      `photo9` varchar(100) default NULL,

      PRIMARY KEY  (`id`)

    ) ENGINE=MyISAM AUTO_INCREMENT=80 DEFAULT CHARSET=latin1 AUTO_INCREMENT=80 ;

     

    #

    This is my add_property code.

    <input name="id" type="text" id="id" size="3" />

     

    and this is my proccess file code

     

    <?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 = "restricted.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 
    //***FUNCTIONS
    
    //filter extensions
    function valid_ext($file_name)
    {
    $valid = array("jpeg","jpg","png","gif");
    $extension = strtolower(substr($file_name,-3,3));
    return (in_array($extension, $valid));
    }
    
    
    //filter by size,
    function valid_size($size)
    {
    return ($size <= 1048576);
    }
    
    
    //This is the directory where images will be saved 
    $path = '../images/';
    
    
    //This gets all the other information from the form 
    $id=$_POST['id']; 
    $name=$_POST['name']; 
    $rank=$_POST['rank']; 
    $suburb=$_POST['suburb']; 
    $price=$_POST['price']; 
    $content=$_POST['content']; 
    $content2=$_POST['content2']; 
    $agentmobile=$_POST['agentmobile']; 
    $agentemail=$_POST['agentemail']; 
    $uploadFile0=($_FILES['uploadFile0']['name']); 
    $uploadFile1=($_FILES['uploadFile1']['name']);
    $uploadFile2=($_FILES['uploadFile2']['name']); 
    $uploadFile3=($_FILES['uploadFile3']['name']);
    $uploadFile4=($_FILES['uploadFile4']['name']);
    $uploadFile5=($_FILES['uploadFile5']['name']);
    $uploadFile6=($_FILES['uploadFile6']['name']);
    $uploadFile7=($_FILES['uploadFile7']['name']);
    $uploadFile8=($_FILES['uploadFile8']['name']);
    
    // Connects to your Database 
    mysql_connect("localhost", "root", "5050888202") or die(mysql_error()) ; 
    mysql_select_db("gcproperty") or die(mysql_error()) ; 
    
     //Writes the information to the database
    
    
    mysql_query("INSERT INTO `employees` VALUES ('$id','$name', '$rank', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')");
    
    // Uploads Images
    $uploadNeed = $_POST['uploadNeed'];
    
    // start for loop
    $copied = 0;//the number of files successfully uploaded
    for($x=0;$x<$uploadNeed;$x++)
    {
    $file_name = $_FILES['uploadFile'. $x]['name'];
    
    //test
    $Size = $_FILES['uploadFile'. $x]['size'];
    
    //Test Check
    $Valid = false;
    if(valid_ext($file_name))
    {
    	echo " {$file_name} valid ext";
    	$Valid = true;
    }else{
    	print "<meta http-equiv=\"refresh\" content=\"0;URL=invalid_extension.php\">";
        exit();
    }
    echo "</br>";
    if(valid_size($Size))
    {
    	echo " {$file_name} valid size</br>";
    }else{
    	$Valid = false;
    	print "<meta http-equiv=\"refresh\" content=\"0;URL=invalid_size.php\">";
    	exit(); 
    }
    if($Valid)
    {
    	// strip file_name of slashes
    	$file_name = stripslashes($file_name);
    	$file_name = str_replace("'","",$file_name);
    	if(file_exists($path . $file_name) ) {
    		print "<meta http-equiv=\"refresh\" content=\"0;URL=file_exists.php\">";
            exit();
    	}else {
    		$copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name);
    		$copied++;//increment our counter
    	}	
    }
    }
    
    
    
    if($copied > 0) {
    
    //do your insert stuff
    
    if($copied != $uploadNeed) {
    
    $not_uploaded = $uploadNeed - $copied;
    
    		print "<meta http-equiv=\"refresh\" content=\"0;URL=upload_error.php\">";
            exit();
    
    
      }
    
    }
    
    
    // check if successfully copied
    
    if($copied == $uploadNeed)
    {
     print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">";
    
    }else{
    
                echo "<br>$file_name The File(s) could not be uploaded!<br>The file must be under 1 meg and be of a valid extension type, jpeg, jpg, png or gif!<br />
    <br />
    Please go <a href=\"property_add.php\">back</a> and try again";
    }
    
    
    
    // end of loop
    
    
    
    ?>

  14. I want to resize a image to fit in an area with javascript.

    I have this code

    <select name="picslist" size="15" style="width: 200px" onClick="showpicture(this)">

    </select>

    Can i implement onClick to resize image to 200px also?

×
×
  • 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.