Jump to content

mdmartiny

Members
  • Posts

    188
  • Joined

  • Last visited

Posts posted by mdmartiny

  1.  

    I still get the same thing..... they are all in a folder called CMS. All the files are in one folder except for the include files and images.

     

    The layout looks like

      CMS

          include

          all of my files

     

        the db_images folder is in the root folder of the system

     

    I changed

    <img src = "<?PHP echo $path ."/" . $file; ?>">

     

    to

     

    <img src = "<?PHP echo $path ."../" . $file; ?>">

     

    to see if that would work and it did not

     

    I probably should of mentioned this earlier... when I was only doing one image. It uploaded fine to the directory it has only started since I been trying to make it more than one

  2. I still get the same thing..... they are all in a folder called CMS. All the files are in one folder except for the include files and images.

     

    The layout looks like

      CMS

          include

          all of my files

     

        the db_images folder is in the root folder of the system

     

    I changed

    <img src = "<?PHP echo $path ."/" . $file; ?>">

     

    to

     

    <img src = "<?PHP echo $path ."../" . $file; ?>">

     

    to see if that would work and it did not

  3. I changed my code and added to it. Now the code is not working at all.

     

    It is not putting the files in the folder on my server. When it writes to the database it creates a new record but nothing is inside of that record all of the fields are blank.

     

    What am I doing wrong?

     

    Here is how my code looks now

    <?PHP
    session_start();
    
    require('includes/connection.php');
    
    $title = $_POST['title'];
    $year = $_POST['year'];
    $make = $_POST['make'];
    $model = $_POST['model'];
    $descript = $_POST['descript'];
    $max_files = $_POST['max_no_img'];
    $valid_types = array ("image/gif", "image/jpg", "image/jpeg", "image/bmp");
    $max_size = 2000000;
    $path = "/home/content/m/i/k/mikedmartiny/html/db_images";
    $i=0;
    
    while($i<$max_files) {
    if ($_FILES['images']['name'][$i] != '') { /* check if file name field empty or not */
    if (in_array($_FILES['images']['type'][$i], $valid_types)) { /* check for valid image type */
    	if($_FILES['images']['size'][$i]<=$max_size) { /* check for allowed size */
    		$check_name = $_FILES['images']['name'][$i];
    		$check_name = preg_replace("/[^a-zA-Z0-9\.]/", "", $check_name);
    		$good = 0;
    		while($good==0) {
    			if(!file_exists($path . $check_name)) { /* check file that file name already exists *
    			   /* move the file */
    			   if (copy($_FILES['images']['tmp_name'][$i], $check_name)) {
    				   $all_images = $all_images . $check_name . ",";
    					  $good=1;
    				   }else{
    					   die ("CHECK WRITE PERMISSIONS OF IMAGE FOLDER!");
    					   }
    				}else{ /* create new name */
    					$check_name = date("YmdHis") . $_FILES['images']['name'][$i];
    					$check_name = preg_replace("/[^a-zA-Z0-9\.]/", "", $check_name);
    				}
    			}
    	}else{
    		die ("FILE SIZE IS TO LARGE. REZIZE IMAGE!");
    		}
    }else{
    	die("INVALID IMAGE FORMAT. IMAGES MUST BE .JPG, .GIF, .BMP OR .PNG!");
    }
    }else{
    die("ALL FIELDS ARE REQUIRED!");
    }
    $i ++;
    }
    
    $sql = "INSERT INTO $table (id, title, year, make, model, descript, image, image_two) VALUES ('', '$_POST[title]', '$_POST[year]', '$_POST[make]', '$_POST[model]', '$_POST[descript]', '" . $images['name'] . "', '" . $images['name'] . "')";
    
    $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
    
    ?>
    <!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>Classified Added</title>
    </head>
    <body>
    <div>
       <h3>The following information has been added to the <?php echo "$table"; ?></h3>
       <p> <strong>Title:</strong> <?php echo "$title"; ?> </p>
       <p> <strong>Year:</strong> <?php echo "$year"; ?> </p>
       <p> <strong>Make:</strong> <?php echo "$make"; ?> </p>
       <p> <strong>Model:</strong> <?php echo "$model"; ?> </p>
       <p> <strong>Description:</strong> <?php echo "$descript"; ?> </p>
       <p> <strong>Image 1:</strong> <?php echo "<img src=\"../db_images/" . $image['name'] . "\">"; ?></p>
       <p> <strong>Image 2: </strong> <?php echo "<img src=\"../db_images/" . $image['name'] . "\">"; ?></p>
       <p><a href="show_add.php">Add another classified ad</a></p>
       <p><a href="admin_menu.php">Return to main menu</a></p>
    </div>
    </body>
    </html>
    

     

    One more things can I put HTML code on die messages? I would like to add like a return to previous page button or something like that so they do not have to hot the back button.

     

    Thank you for all of your help with this

  4. here is the form

     

    <?php
    
    //session start
    session_start();
    
    if (isset($_SESSION['error'])){
    echo "<span id=\"error\"><p>" . $_SESSION['error'] . "</p></span>";
    unset($_SESSION['error']);
    }
    
    $max_no_img = 6;
    
    ?>
    <!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>Add Classified Ad</title>
    </head>
    <body>
    <h1>Add Classified Ad</h1>
    <h2><em>Add a Ad</em></h2>
    
    <?php
    echo "<form method=\"POST\" action=\"add_ad.php\" enctype=\"multipart/form-data\">
       <p> <strong>Title:</strong>
          <input type=\"text\" name=\"title\" id=\"title\" length=\"25\" maxlength=\"25\" />
       </p>
       <p> <strong>Year:</strong>
          <input type=\"text\" name=\"year\" id=\"year\" length=\"25\" maxlength=\"25\" />
       </p>
       <p> <strong>Make</strong>
          <input type=\"text\" name=\"make\" id=\"make\" length=\"25\" maxlength=\"25\" />
       </p>
       <p> <strong>Model:</strong>
          <input type=\"text\" name=\"model\" id=\"model\" length=\"25\" maxlength=\"25\" />
       </p>
       <p> <strong>Description:</strong>
          <textarea name=\"descript\" id=\"descript\" rows=\"5\" cols=\"75\"></textarea>
       </p>";
       for ($i = 1; $i <= $max_no_img; $i++){
    echo "<p><strong>Image $i</strong><br />
       <input type=\"file\" name=\"image[]\" id=\"image[]\" />
    </p>";
       }
       ?>
       <p><input type="submit" name="submit" id="name" value="Add Ad" /></p>
    </form>
       <p><a href="admin_menu.php">Return to Administration Menu</a></p>
       
    </body>
    </html>
    
    

  5. here it is

     

    <?php
    
    //Check to make sure title is filled in. If not redirects to show_add.php
    if (!$_POST[title]) {
    header("Location: show_add.php");
    exit;
    } else {
    //check and see if a session has started
    session_start();
    }
    //if session has not been properly started redirects back to the administration menu
    if ($_SESSION[valid] != "yes") {
    header("Location: admin_menu.php");
    exit;
    }
    
    include('includes/connection.php');
    
    
    //check and see if the type of uploaded file is an image
    function is_valid_type($file) {
    $valid_types = array("image/jpg", "image/jpeg", "image/gif", "image/bmp");
    
    if (in_array($file['type'], $valid_types))
    	return 1;
    return 0;
    }
    
    //Set Constants
    $TARGET_PATH = "/home/content/m/i/k/mikedmartiny/html/db_images/";
    
    $title = $_POST['title'];
    $year = $_POST['year'];
    $make = $_POST['make'];
    $model = $_POST['model'];
    $descript = $_POST['descript'];
    $image = $_FILES['image'];
    
    //Sanitize the inputs
    $title = mysql_real_escape_string($title);
    $year = mysql_real_escape_string($year);
    $make = mysql_real_escape_string($make);
    $model = mysql_real_escape_string($model);
    $descript = mysql_real_escape_string($descript);
    
    //$target_path full string
    $TARGET_PATH .= $image['name'];
    
    //make sure that all fields from form are filled in
    if ( $title == "" || $year == "" || $make =="" || $model == "" || $descript == "" || $image['name'] == "") {
    $_SESSION['error']  = "ALL FIELDS ARE REQUIRED!";
    header ("Location: show_add.php");
    exit;
    }
    
    //check to make sure it has the right file type
    if (!is_valid_type($image)){
    $_SESSION['error'] = "You must upload a jpeg, gif, or bmp";
    header ("Location: show_add.php");
    exit;
    }
    
    //check to see if a file with that name exsists
    if (file_exists($TARGET_PATH)){
    $_SESSION['error'] = "A FILE WITH THAT NAME ALL READY EXIST!";
    header ("Location: show_add.php");
    exit;
    }
    
    //move the image - write path to database
    while(list($key,$value) = each($_FILES[image][name])) {
    if (!empty($value)) {
    	$filename = $value;
    	$filename = str_replace(" ","_",$filename);
    	$add = $TARGET_PATH;
    	copy($_FILES[images][tmp_name][$key], $add);
    }
    } 
    
    $sql = "INSERT INTO $table (id, title, year, make, model, descript, image, image_two) VALUES ('', '$_POST[title]', '$_POST[year]', '$_POST[make]', '$_POST[model]', '$_POST[descript]', '" . $image['name'] . "', '" . $image['name'] . "')";
    
    $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
    
    ?>
    <!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>Classified Added</title>
    </head>
    <body>
    <div>
       <h3>The following information has been added to the <?php echo "$table"; ?></h3>
       <p> <strong>Title:</strong> <?php echo "$title"; ?> </p>
       <p> <strong>Year:</strong> <?php echo "$year"; ?> </p>
       <p> <strong>Make:</strong> <?php echo "$make"; ?> </p>
       <p> <strong>Model:</strong> <?php echo "$model"; ?> </p>
       <p> <strong>Description:</strong> <?php echo "$descript"; ?> </p>
       <p> <strong>Image:</strong> <?php echo "<img src=\"../db_images/" . $image['name'] . "\">"; ?></p>
       <p><a href="show_add.php">Add another classified ad</a></p>
       <p><a href="admin_menu.php">Return to main menu</a></p>
    </div>
    </body>
    </html>
    

  6. I am in the process of writing a CMS for a friend that is looking to add a classified section to his site. He will be the only one that will ever use it.

     

    I got the code to work with one image when he asked me if I could do it so he could post 6 images for each item. I am unable to figure out how to do this. I was told to do this with a while loop.

     

    This is the code that I have written so far.

    <?php
    
    //Check to make sure title is filled in. If not redirects to show_add.php
    if (!$_POST[title]) {
    header("Location: show_add.php");
    exit;
    } else {
    //check and see if a session has started
    session_start();
    }
    //if session has not been properly started redirects back to the administration menu
    if ($_SESSION[valid] != "yes") {
    header("Location: admin_menu.php");
    exit;
    }
    
    include('includes/connection.php');
    
    
    //check and see if the type of uploaded file is an image
    function is_valid_type($file) {
    $valid_types = array("image/jpg", "image/jpeg", "image/gif", "image/bmp");
    
    if (in_array($file['type'], $valid_types))
    	return 1;
    return 0;
    }
    
    //Set Constants
    $TARGET_PATH = "/home/content/m/i/k/mikedmartiny/html/db_images/";
    
    $title = $_POST['title'];
    $year = $_POST['year'];
    $make = $_POST['make'];
    $model = $_POST['model'];
    $descript = $_POST['descript'];
    $image = $_FILES['image'];
    
    //Sanitize the inputs
    $title = mysql_real_escape_string($title);
    $year = mysql_real_escape_string($year);
    $make = mysql_real_escape_string($make);
    $model = mysql_real_escape_string($model);
    $descript = mysql_real_escape_string($descript);
    $image['name'] = mysql_real_escape_string($image['name']);
    
    //$target_path full string
    $TARGET_PATH .= $image['name'];
    
    //make sure that all fields from form are filled in
    if ( $title == "" || $year == "" || $make =="" || $model == "" || $descript == "" || $image['name'] == "") {
    $_SESSION['error']  = "ALL FIELDS ARE REQUIRED!";
    header ("Location: show_add.php");
    exit;
    }
    
    //check to make sure it has the right file type
    if (!is_valid_type($image)){
    $_SESSION['error'] = "You must upload a jpeg, gif, or bmp";
    header ("Location: show_add.php");
    exit;
    }
    
    //check to see if a file with that name exsists
    if (file_exists($TARGET_PATH)){
    $_SESSION['error'] = "A FILE WITH THAT NAME ALL READY EXIST!";
    header ("Location: show_add.php");
    exit;
    }
    
    //move the image - write path to database
    while($image <=2) {
    move_uploaded_file($image['tmp_name'], $TARGET_PATH)
    } else {
    // Make sure you chmod the directory to be writeable
    $_SESSION['error'] = "COULD NOT UPLOAD FILE. CHECK WRITE/REWRITE PERMISSIONS ON THE FILE DIRECTORY!";
    header ("Location: show_add.php");
    exit;
    }
    
    $sql = "INSERT INTO $table (id, title, year, make, model, descript, image, image_two) VALUES ('', '$_POST[title]', '$_POST[year]', '$_POST[make]', '$_POST[model]', '$_POST[descript]', '" . $image['name'] . "', '" . $image['name'] . "')";
    
    $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
    
    ?>
    

     

    I only have it set up to work with 2 images right now. I thought it would be easier to get it to work properly. Then I could just add in the rest of the info later.

     

    Any help would be greatly appreciated.

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