Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Necesito me puedan ayudar con codigo

Estas en el tema de Necesito me puedan ayudar con codigo en el foro de PHP en Foros del Web. Hola a todos, tengo un código de un formulario que me sirve para subir archivos pdf a mi servidor, el tema es que sube el ...
  #1 (permalink)  
Antiguo 25/02/2013, 16:05
 
Fecha de Ingreso: mayo-2008
Mensajes: 199
Antigüedad: 16 años
Puntos: 0
Necesito me puedan ayudar con codigo

Hola a todos, tengo un código de un formulario que me sirve para subir archivos pdf a mi servidor, el tema es que sube el archivo bien a la carpeta que le marque, pero los archivos no los sobrescribe. Necesito subir solo un archivo, siempre es el mismo, pero cada vez que lo subo me lo guarda agregando un numero a lo ultimo del nombre del archivo.

Por favor, como hago para que al subir el mismo archivo, lo sobrescriba siempre?

Dejo el código:


[PHP]<?php
/**
* CoffeeCup Flash Form Builder: Form Results Handler
*
* This file is in charge of handling the form results
* posted from the CoffeeCup Flash Form Builder SWF.
* It has several primary functions:
*
* - Assure that the user is running the proper version of
* PHP and has properly configured their server for
* CoffeeCup Flash Form Builder by uploading the provided
* files and assigning the appropriate server settings
* and permissions.
* - Upload a file if the '$_FILES['Filedata']' variable is
* populated
* - If the '$_POST' superglobal array has been populated,
* process the form by:
* - Reading the config file provided in the '$_POST['xmlfile']'
* variable.
* - Saving the form data to a file if the 'CC_FB_SAVE_FILE' constant
* has been populated.
* - Saving the form data to the database provided in 'CC_FB_DB_ADDRESS'
* if the 'CC_FB_DB_ADDRESS' constant is populated.
* - Emailing the form data to the form owner via the address provided
* in the '$_POST['_ALT_EMAIL']' variable or the '$_POST['mailto']'
* variable if the '$_POST['_ALT_EMAIL']' variable is not populated.
* - Emailing the form data to the form user via the address provided in
* the '$_POST['eM']' variable if the '$_POST['eM']' variable has been
* populated and the 'emailuser' config option is set to 'true'.
* - Taking the form user to the landing page provided in the
* '$_POST['thankyoupage']' variable or to a default landing page
* if the '$_POST['thankyoupage']' is empty.
* - Prints out an informational page with version numbers and release
* dates if an error occurs or if this script is called without
* the '$_POST' superglobal or the '$_FILES['Filedata']' variables
* being set.
*
* @license http://www.coffeecup.com/legal/eula.html
* @author Jeff Welch <[email protected]>
* @version 4.0
* @package CC_FB
*/

// Error reporting should be disabled in favor of
// our customer error messages.
error_reporting(0);

/**
* The version of CoffeeCup Flash Form Builder that
* generated this script.
*/
define('CC_FB_VERSION', '8.0');
/**
* The release date of the version of CoffeeCup Flash Form
* Builder that generated this script.
*/
define('CC_FB_LAST_UPDATED', '02/09/2010');

/**
* The version of this script.
*/
define('CC_FB_SCRIPT_VERSION', '5.1');
/**
* The release date of this script.
*/
define('CC_FB_SCRIPT_LAST_UPDATED', '02/09/2010');

/**
* Will the owner of this form be emailed the
* form data
*/
define('CC_FB_DO_EMAIL',false);
/**
* To default To address.
*/
define('CC_FB_TO_EMAIL', '');
/**
* The default CC address.
*/
define('CC_FB_CC_EMAIL', '');
/**
* The default BCC address.
*/
define('CC_FB_BCC_EMAIL', '');
/**
* The message to send to the form owner
*/
define('CC_FB_OWNER_MESSAGE', '[FORMOWNERMSG]');

/**
* If we should send a message back to the user.
*/
define('CC_FB_AUTO_REPLY', false);
/**
* The subject of the message to be sent to the user.
*/
define('CC_FB_AUTO_REPLY_SUBJECT', '');
/**
* If we should include the form results
* in the message we send to the user.
*/
define('CC_FB_AUTO_REPLY_FORM_RESULTS', false);
/**
* The position of the auto-reply message
* in the email.
*/
define('CC_FB_AUTO_REPLY_POSITION', 'bottom');

/**
* The page to redirect to after the form is submitted.
*/
define('CC_FB_RESULTS_REDIRECT', '[RESULTSREDIRECT]');

/**
* The address of the database where the form results
* will be saved.
*/
define('CC_FB_DB_ADDRESS', '[ADDRESS]');
/**
* The port number of the database where the form results
* will be saved.
*/
define('CC_FB_DB_PORT', '[DBPORT]');
/**
* The username for the database where the form results
* will be saved.
*/
define('CC_FB_DB_USERNAME', '[DBUSER]');
/**
* The password for the database where the form results
* will be saved.
*/
define('CC_FB_DB_PASSWORD', '[DBPASS]');
/**
* The name of the database where the form results
* will be saved.
*/
define('CC_FB_DB_NAME', '[DBNAME]');
/**
* The name of the database table where the form results
* will be saved.
*/
define('CC_FB_DB_TABLE', '[DBTABLE]');

/**
* The file to log the form results to if necessary.
*/
define('CC_FB_SAVE_FILE', '[FILENAME]');

/**
* The filetypes that are acceptable for file uploads.
*/
define('CC_FB_ACCEPTABLE_FILE_TYPES', 'pdf');
/**
* The directory where files are uploaded
*/
define('CC_FB_UPLOADS_DIRECTORY', 'paquetes');
/**
* The extension that gets added to file uploads
*/
define('CC_FB_UPLOADS_EXTENSION', '_utt');
/**
* Will we save the file uploads to the server
*/
define('CC_FB_ATTACHMENT_SAVETOSERVER',true);
/**
* Will we save the file uploads to the db
*/
define('CC_FB_ATTACHMENT_SAVETODB',false);
/**
* Will we send the file upload as an attachment
*/
define('CC_FB_ATTACHMENT_ADDTOEMAIL',false);
/**
* Sendmail Message EOL's
*/
define('CC_FB_SENDMAIL_EOL',"\r\n");

// Makes sure that the user is using the required version
// of PHP as specified by {@link CC_FB_PHP_VERSION}.
if(!version_compare(PHP_VERSION, CC_FB_PHP_VERSION, '>='))
{
printMessage('Invalid PHP Version',
"We're sorry but CoffeeCup Form Builder requires PHP version " .
CC_FB_PHP_VERSION . ' or greater. Please contact your server ' .
'administrator.');
}
// Strip slashes if the server has magic quotes enabled.
if(get_magic_quotes_gpc())
{
$_POST = array_map("stripslashes", $_POST);
}
// John will need to fix this in the swf file.
foreach($_POST as $key => $value)
{
$_POST[str_replace('_', ' ', $key)] = $value;
}
// Let's sanitize some header fields before it gets us in any trouble.
foreach(array('eM','_ALT_EMAIL','subject') as $key)
{
if(isset($_POST[$key]))
{
$_POST[$key] = headerEscape($_POST[$key]);
}
}



Aquí en esta lineas, vi que puede estar la solución:

Código PHP:
The filetypes that are acceptable for file uploads.
    */
   
define('CC_FB_ACCEPTABLE_FILE_TYPES''pdf');
   
/**
    * The directory where files are uploaded
    */
   
define('CC_FB_UPLOADS_DIRECTORY''paquetes');
   
/**
    * The extension that gets added to file uploads
    */
   
define('CC_FB_UPLOADS_EXTENSION''_utt');   
   
/**
    * Will we save the file uploads to the server
    */   
    
define('CC_FB_ATTACHMENT_SAVETOSERVER',true); 
   
/** 

Muchas gracias, besos.
  #2 (permalink)  
Antiguo 25/02/2013, 17:02
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Necesito me puedan ayudar con codigo

Pues no, en lo que muestras de código no está la parte donde se guarda el archivo, sólo son configuraciones iniciales con definición de variables y constantes.

Muestra todo código para poder tratar de ayudar.
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 25/02/2013, 18:19
 
Fecha de Ingreso: mayo-2008
Mensajes: 199
Antigüedad: 16 años
Puntos: 0
Respuesta: Necesito me puedan ayudar con codigo

Hola Triby, gracias por tu respuesta. Puedes descargar el; archivo aqui del código, lo puse en un .txt.

Espero me puedas ayudar, estoy como loca con este codigo.

Gracias.
  #4 (permalink)  
Antiguo 25/02/2013, 18:56
 
Fecha de Ingreso: marzo-2011
Ubicación: Caracas
Mensajes: 389
Antigüedad: 13 años, 2 meses
Puntos: 16
Respuesta: Necesito me puedan ayudar con codigo

Man. Simplemente No lo sobreescribas. Elimina el archivo existente antes de cargar el nuevo.
Código PHP:
Ver original
  1. unlink("nombreDelArchivo");
  2. //luego pones el codigo de carga que ya te funciona.-
Haces eso y no te matas mas.
__________________
Lo imposible es lo posible visto por los ojos de un incapaz.
Si te sirve la respuesta. dale + al karma.
Saludos
  #5 (permalink)  
Antiguo 25/02/2013, 19:41
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Necesito me puedan ayudar con codigo

Busca el siguiente código:

Código PHP:
Ver original
  1. // Append number values on the end of the file name
  2.       // if the file already exists
  3.       while(file_exists(CC_FB_UPLOADS_DIRECTORY . "/$basename" .
  4.          CC_FB_UPLOADS_EXTENSION . "$i$extension"))
  5.       {
  6.          $i++;
  7.       }
  8.  
  9. // Reemplázalo con esto:
  10.  
  11. // Eliminar archivo si ya existe
  12. $i = ''; // Esto es necesario para evitar errores o advertencias
  13. $file = CC_FB_UPLOADS_DIRECTORY . "/$basename" .  CC_FB_UPLOADS_EXTENSION . $extension;
  14.  
  15. if(file_exists($file)) {
  16.     unlink($file);
  17. }
__________________
- León, Guanajuato
- GV-Foto
  #6 (permalink)  
Antiguo 25/02/2013, 19:55
 
Fecha de Ingreso: mayo-2008
Mensajes: 199
Antigüedad: 16 años
Puntos: 0
Respuesta: Necesito me puedan ayudar con codigo

Triby, un genio...ya lo solucione. Muchas gracias a ti y a Rjulio21 por la ayuda y el tiempo.

Naty.

Etiquetas: formulario, html, 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 09:33.