Guest User

Untitled

a guest
Feb 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. function upload_img($id = null)
  2. {
  3. $this->layout = 'empty';
  4. //Configure::write('debug', 0);
  5. if(empty($this->data)) {
  6. die();
  7. }
  8.  
  9. $full = $this->JqImgcrop->uploadImage($this->data['Listing']['image'], 'img/listings/full/', time());
  10.  
  11. # create a 200 width thumbnail
  12. $target = WWW_ROOT.'img/listings/200/'.$full['imageName'];
  13. copy($full['imagePath'], $target);
  14.  
  15. if($full['imageWidth'] >= $full['imageHeight']) {
  16. $scale = 200/$full['imageWidth'];
  17. } else {
  18. $scale = 150/$full['imageHight'];
  19. }
  20.  
  21. $this->JqImgcrop->resizeImage($target, $full['imageWidth'], $full['imageHeight'], $scale);
  22.  
  23. # create a 100 width thumbnail
  24. $target = WWW_ROOT.'img/listings/100/'.$full['imageName'];
  25. copy($full['imagePath'], $target);
  26.  
  27. if($full['imageWidth'] >= $full['imageHeight']) {
  28. $scale = 100/$full['imageWidth'];
  29. } else {
  30. $scale = 75/$full['imageHight'];
  31. }
  32.  
  33. $this->JqImgcrop->resizeImage($target, $full['imageWidth'], $full['imageHeight'], $scale);
  34.  
  35. # write to listing images table
  36. $data = $this->ListingImage->create(array(
  37. 'ListingImage'=>array(
  38. 'filename' => $full['imageName'],
  39. 'listing_id'=>$id
  40. )
  41. ));
  42. $this->ListingImage->save($data);
  43. $images = $this->ListingImage->findAllByListing_id($id);
  44.  
  45. # output image gallery thumbs
  46. $this->set('images', $images);
  47. }
  48.  
  49. /**
  50. * View
  51. */
  52. <p>
  53. <?php foreach($images as $img): ?>
  54. <img src="/img/listings/100/<?php echo $img['ListingImage']['filename']; ?>" />
  55. <?php endforeach; ?>
  56. </p>
  57.  
  58. /**
  59. * View with Thickbox
  60. */
  61. <?php $html->addCrumb("My Renterval", "/users/"); ?>
  62. <?php $html->addCrumb('Create a New Listing (Step 2)', '/listings/step2/'.$l['Listing']['id']); ?>
  63.  
  64. <?php $javascript->link('form/jquery.form.js', false); ?>
  65. <?php $javascript->link('form/upload.image.js', false); ?>
  66. <?php $javascript->link('img/imgareaselect.min.js', false); ?>
  67.  
  68. <div id="yui-main">
  69. <div class="yui-b">
  70. <h2>Create a New Listing - Step 2</h2>
  71. <h3><?php echo $l['Listing']['title']; ?></h3>
  72. <?php echo !empty($errors) ? pr($errors) : ''; ?>
  73. <form method="post" action="/listings/step2/<?php echo $l['Listing']['id']; ?>">
  74.  
  75. <label>Service or Equipment</label>
  76.  
  77. <input id="listing-type-equipment" type="radio" name="data[Listing][type]" value="equipment"
  78. <?php echo ($this->data['Listing']['type'] == 'equipment') ? 'checked' : ''; ?> />
  79. <label for="listing-type-equipment" style="display:inline;">Equipment</label>
  80.  
  81. <input id="listing-type-service" type="radio" name="data[Listing][type]" value="service"
  82. <?php echo ($this->data['Listing']['type'] == 'service') ? 'checked' : ''; ?> />
  83. <label for="listing-type-service" style="display:inline;">Service</label>
  84.  
  85. <label>Manufacturer (if applicable)</label>
  86. <input type="text" name="data[Listing][manufacturer]" value="<?php echo $this->data['Listing']['manufacturer']; ?>" />
  87.  
  88. <label for="listing-tags-input">Tags</label>
  89. <input id="listing-tags-input" type="text" name="data[Listing][tag_string]"
  90. value="<?php echo $this->data['Listing']['tag_string']; ?>" />
  91.  
  92. <label for="listing-description-input">Description</label>
  93. <textarea id="listing-description-input" name="data[Listing][description]"><?php echo $this->data['Listing']['description']; ?></textarea>
  94.  
  95. <label>Images</label>
  96. <a href="/listings/upload_img#TB_inline?inlineId=uploadImageDiv" class="thickbox">Upload an Image</a>
  97. <div id="imageThumbs">
  98. <p>
  99. <?php foreach($images as $img): ?>
  100. <img src="/img/listings/100/<?php echo $img['ListingImage']['filename']; ?>" />
  101. <?php endforeach; ?>
  102. </p>
  103. </div>
  104. <div class="cl"></div>
  105. <input type="button" value="Back to Step 1" onclick="window.location='/listings/create/<?php echo $l['Listing']['id']; ?>'"/>
  106. <input type="submit" value="Continue to Step 3" />
  107. </form>
  108. </div>
  109. </div>
  110. <div class="yui-b right-sidebar">
  111. <div class="yui-b">
  112.  
  113. </div>
  114. </div>
  115.  
  116. <div id="uploadImageDiv" style="display:none;">
  117. <div class="yui-b" id="uploadImageFormWrapper">
  118. <h2>Upload an Image</h2>
  119. <form action="/listings/upload_img/<?php echo $l['Listing']['id']; ?>" method="post" id="uploadImageForm" enctype="multipart/form-data">
  120. <label for="ListingImage">Image</label>
  121. <input type="file" id="ListingImage" value="" name="data[Listing][image]"/>
  122. <div class="cl"></div>
  123. <input type="submit" value="Upload"/>
  124. <input type="button" value="Cancel" onclick="tb_remove();" />
  125. </form>
  126. </div>
  127. </div>
Add Comment
Please, Sign In to add comment