SHARETHIS.addEntry({ title: "phpLD Image Uploader MOD", url: "http://criticdirectory.net/2007/04/26/phpld-mods/phpld-image-uploader-mod.html" });"/>
Apr 26 2007

phpLD Image Uploader MOD

With this modification you can allow users to upload a profile image that will be placed in their details page.

1. Create a folder called uploads in the same folder as submit.php (root of the directory)

2. chmod 777 uploads

3. create a file image_upload.php in the same folder as submit.php, with the content below:

<?php $error=$_FILES[”IMAGE”][”error”];

if ($error == UPLOAD_ERR_OK) {

 $parsed = parse_url($_POST[”URL”]);

 $image_domain = $parsed[’host’];

 $image_type=$_FILES[’IMAGE’][’type’];

 $image_loc=”uploads/”.$image_domain.”.jpg”;

 $tmp_name = $_FILES[”IMAGE”][”tmp_name”];

  if ($image_type ==”image/pjpeg” ||

      $image_type==”image/gif”    ||

      $image_type==”image/png”){

    move_uploaded_file($tmp_name, $image_loc);

  }

}

?>

4. in submit.php,

AFTER: require_once 'init.php';

ADD: require_once "image_upload.php";

5. in submit.tpl

FIND :

<form action="" method="post">

REPLACE BY:

<form action="" method="post"

          enctype="multipart/form-data">

FIND:

<td class="field">

      {* Load category selection *}

      {include file="category_select.tpl"}

   </td>

   </tr>

AFTER it, ADD:

<tr>

 <td class="label">Image</td>

 <td class="field">

  <input type="file" name="IMAGE" />

 </td></tr>

7. in detail.tpl, where you want the image to appear.

ADD:

{php}

$uploads_path="/path/to/uploads/";

$parsed = parse_url($this->_tpl_vars[URL]);

$image_domain = $parsed['host'];

$abs_image_loc = $uploads_path.$image_domain.".jpg";

$image_loc = "../uploads/".$image_domain.".jpg";

if (file_exists($abs_image_loc)) {

  echo "<img src=\"" . $image_loc . "\" />";

}

{/php}

EDIT : $uploads_path=”/path/to/uploads/”;

in the code above to something to the absolute path

to your uploads folder something like

“/home/domain/public_html/uploads/”

That’s it.

The mod can be improved by adding small test on the image size and dimensions.

TAGS:

LEAVE A COMMENT

You must be logged in to post a comment.

Categories

Archives