Ver Mensaje Individual
  #4 (permalink)  
Antiguo 17/02/2012, 16:37
Avatar de VbOkonly
VbOkonly
 
Fecha de Ingreso: julio-2009
Ubicación: San Justo, Buenos Aires, Argentina
Mensajes: 490
Antigüedad: 14 años, 10 meses
Puntos: 5
Respuesta: Problema con uploadify PHP+AJAX+MySQL

te juro que estoy llorando, me funcionoooo!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

esta es la solucion:

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.         // <![CDATA[
  3.     $(document).ready(function() {
  4.       $('#file_upload').uploadify({
  5.         'uploader'  : 'dify/uploadify.swf',
  6.         'script'    : 'dify/uploadify.php',
  7.         'cancelImg' : 'dify/cancel.png',
  8.         'folder'    : '/uploads',
  9.         'buttonText': 'Cambiar Foto',
  10.         'sizeLimit' : '5242880',
  11.         'scriptData'  : {'fid':<?php echo $getUsuario;?>},
  12.         'displayData': 'percentage',
  13.         'fileExt'     : '*.jpg;*.gif;*.png;*jpeg',
  14.         'fileDesc'    : 'Image Files',
  15.         'onComplete'  : function(event, ID, fileObj, response, data) {     
  16.         window.location.reload();
  17.         },
  18.         'auto'      : true
  19.       });
  20.     });
  21.     // ]]>
  22.     </script>

Bien, ahora me falta solo la parte de PHP donde tengo la clase esa, no se como obtener las dos rutas de las imagenes, como puedo hacerlo?, este es el script:

Código PHP:
Ver original
  1. <?php
  2. /*
  3. Uploadify v2.1.4
  4. Release Date: November 8, 2010
  5.  
  6. Copyright (c) 2010 Ronnie Garcia, Travis Nickels
  7.  
  8. Permission is hereby granted, free of charge, to any person obtaining a copy
  9. of this software and associated documentation files (the "Software"), to deal
  10. in the Software without restriction, including without limitation the rights
  11. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. copies of the Software, and to permit persons to whom the Software is
  13. furnished to do so, subject to the following conditions:
  14.  
  15. The above copyright notice and this permission notice shall be included in
  16. all copies or substantial portions of the Software.
  17.  
  18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. THE SOFTWARE.
  25. */
  26. if (!empty($_FILES)) {
  27.  
  28.         class Image {
  29.            
  30.             var $uploaddir;
  31.             var $quality = 100;
  32.             var $ext;
  33.             var $dst_r;
  34.             var $img_r;
  35.             var $img_w;
  36.             var $img_h;
  37.             var $output;
  38.             var $data;
  39.             var $datathumb;
  40.            
  41.             function setFile($src = null) {
  42.                 $this->ext = strtoupper(pathinfo($src, PATHINFO_EXTENSION));
  43.                 if(is_file($src) && ($this->ext == "JPG" OR $this->ext == "JPEG")) {
  44.                     $this->img_r = ImageCreateFromJPEG($src);
  45.                 } elseif(is_file($src) && $this->ext == "PNG") {
  46.                     $this->img_r = ImageCreateFromPNG($src);      
  47.                 } elseif(is_file($src) && $this->ext == "GIF") {
  48.                     $this->img_r = ImageCreateFromGIF($src);
  49.                 }
  50.                 $this->img_w = imagesx($this->img_r);
  51.                 $this->img_h = imagesy($this->img_r);
  52.             }
  53.            
  54.             function resize($w = 100) {
  55.                 $h =  $this->img_h / ($this->img_w / $w);
  56.                 $this->dst_r = ImageCreateTrueColor($w, $h);
  57.                 imagecopyresampled($this->dst_r, $this->img_r, 0, 0, 0, 0, $w, $h, $this->img_w, $this->img_h);
  58.                 $this->img_r = $this->dst_r;
  59.                 $this->img_h = $h;
  60.                 $this->img_w = $w;
  61.             }
  62.            
  63.             function createFile($output_filename = null) {
  64.                 if($this->ext == "JPG" OR $this->ext == "JPEG") {
  65.                     imageJPEG($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext, $this->quality);
  66.                 } elseif($this->ext == "PNG") {
  67.                     imagePNG($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext);
  68.                 } elseif($this->ext == "GIF") {
  69.                     imageGIF($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext);
  70.                 }
  71.                 $this->output = $this->uploaddir.$output_filename.'.'.$this->ext;
  72.             }
  73.            
  74.             function setUploadDir($dirname) {
  75.                 $this->uploaddir = $dirname;
  76.             }
  77.            
  78.             function flush() {
  79.         $tempFile = $_FILES['Filedata']['tmp_name'];
  80.         $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
  81.         $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
  82.                
  83.                 imagedestroy($this->dst_r);
  84.                 unlink($targetFile);
  85.                 //imagedestroy($this->img_r);
  86.                
  87.             }
  88.            
  89.         }  
  90.     $prefijo = substr(md5(uniqid(rand())),0,6);
  91.     $tempFile = $_FILES['Filedata']['tmp_name'];
  92.     $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
  93.     $targetFile =  str_replace('//','/',$targetPath) . $prefijo .'_' . $_FILES['Filedata']['name'];
  94.        
  95.         move_uploaded_file ($tempFile, $targetFile);
  96.        
  97.         $image = new Image();
  98.         $image->setFile($targetFile);
  99.         $image->setUploadDir($targetPath);
  100.         $image->resize(640);
  101.         $image->createFile(md5($tempFile));
  102.         $image->resize(250);
  103.         $image->createFile("s_".md5($tempFile));
  104.         $image->flush();
  105.         }
  106.         $userrr = $_REQUEST['fid'];
  107.         include('conexion.php');
  108.         mysql_query('INSERT fotos SET pertenecea_foto = "'.$userrr.'"',$db);
  109. ?>

La ultima consulta es una prueba para ver si recibia la variable de ajax, bien, lo que deseo ahora es obtener las dos rutas de las dos imagenes, lo malo es que obtengo la ruta de la original y no la de las redimensionadas..

$targetFile es la ruta original, no se de que manera obtener las de las redimensionadas, en total se almacenan 3 imagenes(la original, thumb y otra que esta redimensionada a 640)
__________________
Mi primera web: http://www.mascoteame.com