Created
July 23, 2008 15:31
-
-
Save britg/1786 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function upload_img($id = null) | |
{ | |
$this->layout = 'empty'; | |
//Configure::write('debug', 0); | |
if(empty($this->data)) { | |
die(); | |
} | |
$full = $this->JqImgcrop->uploadImage($this->data['Listing']['image'], 'img/listings/full/', time()); | |
# create a 200 width thumbnail | |
$target = WWW_ROOT.'img/listings/200/'.$full['imageName']; | |
copy($full['imagePath'], $target); | |
if($full['imageWidth'] >= $full['imageHeight']) { | |
$scale = 200/$full['imageWidth']; | |
} else { | |
$scale = 150/$full['imageHight']; | |
} | |
$this->JqImgcrop->resizeImage($target, $full['imageWidth'], $full['imageHeight'], $scale); | |
# create a 100 width thumbnail | |
$target = WWW_ROOT.'img/listings/100/'.$full['imageName']; | |
copy($full['imagePath'], $target); | |
if($full['imageWidth'] >= $full['imageHeight']) { | |
$scale = 100/$full['imageWidth']; | |
} else { | |
$scale = 75/$full['imageHight']; | |
} | |
$this->JqImgcrop->resizeImage($target, $full['imageWidth'], $full['imageHeight'], $scale); | |
# write to listing images table | |
$data = $this->ListingImage->create(array( | |
'ListingImage'=>array( | |
'filename' => $full['imageName'], | |
'listing_id'=>$id | |
) | |
)); | |
$this->ListingImage->save($data); | |
$images = $this->ListingImage->findAllByListing_id($id); | |
# output image gallery thumbs | |
$this->set('images', $images); | |
} | |
/** | |
* View | |
*/ | |
<p> | |
<?php foreach($images as $img): ?> | |
<img src="/img/listings/100/<?php echo $img['ListingImage']['filename']; ?>" /> | |
<?php endforeach; ?> | |
</p> | |
/** | |
* View with Thickbox | |
*/ | |
<?php $html->addCrumb("My Renterval", "/users/"); ?> | |
<?php $html->addCrumb('Create a New Listing (Step 2)', '/listings/step2/'.$l['Listing']['id']); ?> | |
<?php $javascript->link('form/jquery.form.js', false); ?> | |
<?php $javascript->link('form/upload.image.js', false); ?> | |
<?php $javascript->link('img/imgareaselect.min.js', false); ?> | |
<div id="yui-main"> | |
<div class="yui-b"> | |
<h2>Create a New Listing - Step 2</h2> | |
<h3><?php echo $l['Listing']['title']; ?></h3> | |
<?php echo !empty($errors) ? pr($errors) : ''; ?> | |
<form method="post" action="/listings/step2/<?php echo $l['Listing']['id']; ?>"> | |
<label>Service or Equipment</label> | |
<input id="listing-type-equipment" type="radio" name="data[Listing][type]" value="equipment" | |
<?php echo ($this->data['Listing']['type'] == 'equipment') ? 'checked' : ''; ?> /> | |
<label for="listing-type-equipment" style="display:inline;">Equipment</label> | |
<input id="listing-type-service" type="radio" name="data[Listing][type]" value="service" | |
<?php echo ($this->data['Listing']['type'] == 'service') ? 'checked' : ''; ?> /> | |
<label for="listing-type-service" style="display:inline;">Service</label> | |
<label>Manufacturer (if applicable)</label> | |
<input type="text" name="data[Listing][manufacturer]" value="<?php echo $this->data['Listing']['manufacturer']; ?>" /> | |
<label for="listing-tags-input">Tags</label> | |
<input id="listing-tags-input" type="text" name="data[Listing][tag_string]" | |
value="<?php echo $this->data['Listing']['tag_string']; ?>" /> | |
<label for="listing-description-input">Description</label> | |
<textarea id="listing-description-input" name="data[Listing][description]"><?php echo $this->data['Listing']['description']; ?></textarea> | |
<label>Images</label> | |
<a href="/listings/upload_img#TB_inline?inlineId=uploadImageDiv" class="thickbox">Upload an Image</a> | |
<div id="imageThumbs"> | |
<p> | |
<?php foreach($images as $img): ?> | |
<img src="/img/listings/100/<?php echo $img['ListingImage']['filename']; ?>" /> | |
<?php endforeach; ?> | |
</p> | |
</div> | |
<div class="cl"></div> | |
<input type="button" value="Back to Step 1" onclick="window.location='/listings/create/<?php echo $l['Listing']['id']; ?>'"/> | |
<input type="submit" value="Continue to Step 3" /> | |
</form> | |
</div> | |
</div> | |
<div class="yui-b right-sidebar"> | |
<div class="yui-b"> | |
</div> | |
</div> | |
<div id="uploadImageDiv" style="display:none;"> | |
<div class="yui-b" id="uploadImageFormWrapper"> | |
<h2>Upload an Image</h2> | |
<form action="/listings/upload_img/<?php echo $l['Listing']['id']; ?>" method="post" id="uploadImageForm" enctype="multipart/form-data"> | |
<label for="ListingImage">Image</label> | |
<input type="file" id="ListingImage" value="" name="data[Listing][image]"/> | |
<div class="cl"></div> | |
<input type="submit" value="Upload"/> | |
<input type="button" value="Cancel" onclick="tb_remove();" /> | |
</form> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment