Jump to content

uploading image


j05hr

Recommended Posts

Can anyone explain why this wouldn't upload my image to my ftp, it loads the blob into the database so I know the name of the database is ok.  I also made the directory in my ftp called uploads.  So why will the image not upload to the folder?

 

<?php require_once("includes/session.php"); ?>
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php confirm_logged_in(); ?>
<?php
      if (intval($_GET['subj']) == 0) {
         redirect_to("content1.php");
      }
      if (isset($_POST['submit'])) {
         $errors = array();

         $required_fields = array('menu_name', 'position', 'visible', 'content', 'house_price', 'bedrooms', 'propType');
         foreach($required_fields as $fieldname) {
            if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) { 
               $errors[] = $fieldname; 
            }
         }
         $fields_with_lengths = array('menu_name' => 30);
         foreach($fields_with_lengths as $fieldname => $maxlength ) {
            if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; }
         }
         
         if (empty($errors)) {
            // Perform Update
            $id = mysql_prep($_GET['subj']);
            $menu_name = mysql_prep($_POST['menu_name']);
            $position = mysql_prep($_POST['position']);
            $visible = mysql_prep($_POST['visible']);
            $content = mysql_prep($_POST['content']);
            $house_price = str_replace(",", "", $_POST['house_price']);
		$house_price = mysql_prep($house_price);
            $bedrooms = mysql_prep($_POST['bedrooms']);
            $propType = mysql_prep($_POST['propType']);
		$typeofsale = mysql_prep($_POST['typeofsale']);
		$image = mysql_prep($_POST['image']);

		///////////////////////
		///////////////////////
		///////////////////////
		///////////////////////
			if (is_uploaded_file ($_FILES['image']['tmp_name']))
    {
      $message = "The file has been uploaded";
        $test = 'uploads/'.$_FILES['image']['name'];
        //$temp = 'uploads/fred.jpg';
        echo $temp;
        if (move_uploaded_file ($_FILES['image']['tmp_name'], $test))
        {
           $message = "The file has been moved";
        }
        else
        {
            $errors[] = 'The file could not be moved';
            $test = $_FILES['image']['tmp_name'];
            echo 'failed';
        }
        $image = $test;
    }
	/////////////////////////
	/////////////////////////
	/////////////////////////
	/////////////////////////
            
            $query = "UPDATE subjects SET 
                     menu_name = '{$menu_name}', 
                     position = {$position}, 
                     visible = {$visible},
                     content = '{$content}',
                     house_price = '{$house_price}',
                     bedrooms = '{$bedrooms}',
                     propType = '{$propType}',
				 buyRentNew = '{$typeofsale}',
				 image = '{$image}'
                  WHERE id = {$id}";
            $result = mysql_query($query, $connection);
            if (mysql_affected_rows() == 1) {
               // Success
               $message = "The subject was successfully updated.";
            } else {
               // Failed
               $message = "The subject update failed.";
               $message .= "<br />". mysql_error();
            }
            
         } else {
            // Errors occurred
            $message = "There were " . count($errors) . " errors in the form.";
         }
         
         
         
         
      } // end: if (isset($_POST['submit']))
?>
<?php find_selected_page();?>
<?php include("includes/header.php"); ?>
<div id="content">
      <h2> Buying Edit Page</h2>
      <br />
      <h5>Edit Subject: <?php echo $sel_subject ['menu_name']; ?></h5>
         <?php if (!empty($message)) {
            echo "<p class=\"messge\">" . $message . "</p>";
         } ?>
         <?php
         // output a list of the fields that had errors
         if (!empty($errors)) {
            echo "<p class=\"errors\">";
            //echo "Please review the following fields:<br />";
            foreach($errors as $error) {
               echo " - " . $error . "<br />";
            }
            echo "</p>";
         }
         ?>
         <form enctype="multipart/form-data" action="edit_subject.php?subj=<?php echo urlencode($sel_subject['id']);?>" method="post">
            <p>Subject name:
               <input type="text" name="menu_name" value="<?php echo $sel_subject['menu_name']; ?>" id="menu_name" />
            </p>
            <p>House Price:
               <input type="text" name="house_price" value="<?php echo $sel_subject['house_price']; ?>" id="house_price" />
            </p>
            <p>Bedrooms:
               <select name="bedrooms"/>
                  <option <?php echo $sel_subject['bedrooms'] == '1' ? 'selected="selected"' : ''; ?>>1</option>
                  <option <?php echo $sel_subject['bedrooms'] == '2' ? 'selected="selected"' : ''; ?>>2</option>
                  <option <?php echo $sel_subject['bedrooms'] == '3' ? 'selected="selected"' : ''; ?>>3</option>
                  <option <?php echo $sel_subject['bedrooms'] == '4' ? 'selected="selected"' : ''; ?>>4</option>
                  <option <?php echo $sel_subject['bedrooms'] == '5' ? 'selected="selected"' : ''; ?>>5+</option>
               </select>
            </p>
            <p>Type of Property:
               <select name="propType" />
                  <option <?php echo $sel_subject['propType'] == 'House' ? 'House"' : ''; ?>>House</option>
                  <option <?php echo $sel_subject['propType'] == 'Bungalow' ? 'selected="selected"' : ''; ?>>Bungalow</option>
                  <option <?php echo $sel_subject['propType'] == 'Flat' ? 'selected="selected"' : ''; ?>>Flat</option>
                  <option <?php echo $sel_subject['propType'] == 'Detached' ? 'selected="selected"' : ''; ?>>Detached</option>
                  <option <?php echo $sel_subject['propType'] == 'Semi_Detached' ? 'selected="selected"' : ''; ?>>Semi_Detached</option>
                  <option <?php echo $sel_subject['propType'] == 'Terraced' ? 'selected="selected"' : ''; ?>>Terraced</option>
               </select>
            </p>
            <p>Edit content:
               <textarea name="content" rows="10" cols="70"><?php echo $sel_subject['content']; ?> </textarea>
               </p>
            <p>Position:
               <select name="position">
                  <?php
                     $subject_set = get_all_subjects();
                     $subject_count = mysql_num_rows($subject_set);
                     // $subject_count + 1 b/c we are adding a subject
                     for($count=1; $count <= $subject_count+1; $count++) {
                        echo "<option value=\"{$count}\"";
                        if ($sel_subject['position'] == $count) {
                           echo " selected";
                        } 
                        echo ">{$count}</option>";
                     }
                  ?>
               </select>
            </p>
            <p>Visible:
               <input type="radio" name="visible" value="0"<?php 
               if ($sel_subject['visible'] == 0) { echo " checked"; } 
               ?> /> No
                
               <input type="radio" name="visible" value="1"<?php 
               if ($sel_subject['visible'] == 1) { echo " checked"; } 
               ?> /> Yes
            </p>
    <p>Type of Sale: 
	<select name="typeofsale">
		<option value="buy" <?php echo $sel_subject['buyRentNew'] == 'buy' ? 'selected="selected"' : ''; ?>>Buying</option>
		<option value="rent" <?php echo $sel_subject['buyRentNew'] == 'rent' ? 'selected="selected"' : ''; ?>>Renting</option>
		<option value="new" <?php echo $sel_subject['buyRentNew'] == 'new' ? 'selected="selected"' : ''; ?>>New House</option>
	</select>
	</p>
	<p>
	Image:
	<input name="image" accept="image/jpeg" type="file">
	</p>

            <input type="submit" name="submit" value="Update Subject" />
            </p>
            
            <h5 id="link"><a href="delete_subject.php?subj=<?php echo urlencode($sel_subject['id']); ?>" onclick="return confirm('Are you sure?');">Delete Subject</a></h5>
         </form>
         <br />
         <h5 id="link"><a href="edit_page.php?page=<?php echo urlencode($sel_subject['id']); ?>">Edit Page</a></h5>
         <h5 id="link"><a href="content1.php">Cancel</a></h5>
         <h5 id="link"><a href="new_page.php?subj=<?php echo $sel_subject['id']; ?>">+ Add a new page to this subject</a></h5>
</div>

<?php require("includes/footer.php"); ?>

Link to comment
Share on other sites

If you develop and debug your code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the errors php detects will be reported and displayed, php will probably tell you why the move_uploaded_file() function is failing.

Link to comment
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.