Foros del Web » Programando para Internet » PHP »

PHP y Uploadify

Estas en el tema de PHP y Uploadify en el foro de PHP en Foros del Web. Hola, Estoy tratando de implementar un plugin jquery (Uploadify) en mi sitio web. He buscado en la documentacion del plugin y he logrado agregar otra ...
  #1 (permalink)  
Antiguo 15/08/2011, 12:31
 
Fecha de Ingreso: febrero-2011
Mensajes: 64
Antigüedad: 13 años, 1 mes
Puntos: 3
Pregunta PHP y Uploadify

Hola,

Estoy tratando de implementar un plugin jquery (Uploadify) en mi sitio web. He buscado en la documentacion del plugin y he logrado agregar otra forma y guardar datos sus datos en mi base de datos.

Lo siguiente que quiero hacer es pasar la variable del nombre del archivo que estoy subiendo a mi base de datos. No tengo idea de por donde hacerlo. He hecho varias puebas pero sin resultado. Si alguien me ayuda se lo agradesco.

Aqui esta mi codigo:

untitled.php

Código PHP:
<?php require_once('Connections'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "testform")) {
  
$insertSQL sprintf("INSERT INTO borrar (borrar) VALUES (%s)",
                       
GetSQLValueString($_POST['someField'], "text"));

  
mysql_select_db($database);
  
$Result1 mysql_query($insertSQL$ay_que_rico) or die(mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>


<link href="uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript" src="jquery.uploadify.v2.1.4.min.js"></script>


<script type="text/javascript">
$(document).ready(function() {  
    $('#file_upload').uploadify({    
      'uploader'  : 'uploadify.swf',    
      'script'    : 'uploadify.php',    
      'cancelImg' : 'cancel.png',    
      'folder'    : 'uploads',    
      'multi'        : false,
      'fileDataName' : 'Filedata',    
      'onAllComplete' : function() {       
      $('#testform').submit();
      } 
          
    });
   });
</script>


</head>

<body>

<form name="testform" id="testform" action="<?php echo $editFormAction?>" method="POST">
<input name="someField" type="text" />
<input id="file_upload" name="someName" type="file" />
<input onclick="$('#file_upload').uploadifyUpload()" type="button" value="Submit" />
<input type="hidden" name="MM_insert" value="testform" />
</form>

</body>
</html>



uploadify.php

Código PHP:
<?php
/*
Uploadify v2.1.4
Release Date: November 8, 2010

Copyright (c) 2010 Ronnie Garcia, Travis Nickels

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
if (!empty($_FILES)) {
    
$tempFile $_FILES['Filedata']['tmp_name'];
    
$targetPath $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    
$targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
    
    
// $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
    // $fileTypes  = str_replace(';','|',$fileTypes);
    // $typesArray = split('\|',$fileTypes);
    // $fileParts  = pathinfo($_FILES['Filedata']['name']);
    
    // if (in_array($fileParts['extension'],$typesArray)) {
        // Uncomment the following line if you want to make the directory if it doesn't exist
        // mkdir(str_replace('//','/',$targetPath), 0755, true);
        
        
move_uploaded_file($tempFile,$targetFile);
                
        echo 
str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
    
// } else {
    //     echo 'Invalid file type.';
    // }
}
?>
  #2 (permalink)  
Antiguo 16/08/2011, 15:49
 
Fecha de Ingreso: agosto-2011
Mensajes: 1
Antigüedad: 12 años, 8 meses
Puntos: 0
Respuesta: PHP y Uploadify

Hola, lo que debes hacer es colocar toda tu logica de conexión e inserción a la bd en el archivo uploadify.php, y luego capturas la variable que posee el nombre del archivo y asunto arreglado, que tengas buena suerte, saludos.

Etiquetas: html, mysql, sql, uploadify, variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:26.