Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/07/2008, 19:16
Avatar de Marvin
Marvin
Colaborador
 
Fecha de Ingreso: febrero-2005
Ubicación: global $Chile->Santiago;
Mensajes: 1.991
Antigüedad: 19 años, 2 meses
Puntos: 81
Respuesta: Renombrar archivos php desde php

Prueba con esto:
Código PHP:
<? error_reporting(E_ALL); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Llamado a la base de datos</title>
</head>
<body>
<?php
$Noma        
$_POST['Noma'];
$Nomar        $_POST['Nomar'];
$Carpeta    $_POST['Carpeta'];
$Asunto        $_POST['Asunto'];
$Vartable    $_POST['Tabla'];
$link mysql_connect("localhost","root""");
mysql_select_db("clientes",$link) or die("Error: Imposible Conectar");
$sql 'SELECT * FROM `datos_usuario`';
$resEmp mysql_query($sql$link) or die(mysql_error());
$totEmp mysql_num_rows($resEmp);
if (
$totEmp 0){ 
    echo 
"Archivo creado a las: ".date("h:i:s")." del dia ".date(" d \d\e\l\ \m\e\s m \d\e y");
}
echo 
"\\\\\El total de archivos creados es :".$totEmp."<br>";
$Var=$_POST['Tipo'];
$nombre_carpeta="C:/Sitios/$Var/$Carpeta";
if(!
is_dir($nombre_carpeta)){
    @
mkdir($nombre_carpeta0700);
    echo
"";
}else{
    echo 
"";
}

while (
$rowEmp =mysql_fetch_assoc($resEmp)){
    
$nombre_temp=tempnam("C:/Sitios/$Var/$Carpeta","$Nomar");
    
$archivo=$nombre_temp.".php";
    
$gestor fopen($archivo"w");
    
    
//header("Content-type: application/vnd.ms-excel");
    //header("Content-Disposition:; filename=\"$Noma.XLS\";");
    
    
$Var $_POST['Tipo'];
    if(
$Var==Periodismo){
        
$Varusu="periodis_ip"$Varpass="12345"$Vardb="periodis_ip";
    }elseif(
$Var==Postales){
        
$Varusu="postales_ips"$Varpass="12345"$Vardb="postales_ips";
    }elseif(
$Var==Amante){
        
$Varusu="asalvaje_ip"$Varpass="12345"$Vardb="asalvaje_ip"
    }
    echo 
"<table border=1>";
    echo 
"<tr><th> Correo : </th><th> ".$rowEmp['id']." </th><th>el archivo relacionado a este correo es: </th><th>".$nombre_temp."</th></tr>";
    
$str "<?php\n function ObtenerNavegador() { \$navegadores = array( \n'Opera' => 'Opera',\n'Mozilla Firefox'=> '(Firebird)|(Firefox)', \n'Galeon' => 'Galeon', \n'Safari'=>'saf', \n 'MyIE'=>'MyIE', \n'konqueror'=>'konq', \n'netpositive'=>'netp', \n'K-meleon'=>'K-Meleon', \n 'Lynx' => 'Lynx', \n'Netscape'=>'(Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79)', \n'Konqueror'=>'Konqueror', \n 'Internet Explorer 7' => '(MSIE 7\.[0-9]+)', \n'Internet Explorer 6' => '(MSIE 6\.[0-9]+)', \n'Internet Explorer 5' => '(MSIE 5\.[0-9]+)', \n 'Internet Explorer 4' => '(MSIE 4\.[0-9]+)', \n 'amaya'=>'amaya', \n'AOL'=>'AOL', \n'elinks'=>'elinks', \n'links'=>'links', \n'w3m'=>'w3m', \n 'dillo'=>'dillo', \n ' Googlebot'=>'google' \n ); \n foreach($navegadores as \$navegador=>\$pattern){ \nif (eregi(\$pattern, \$_SERVER['HTTP_USER_AGENT'])) \n return \$navegador; \n } \n return 'Desconocido'; \n } \n ?> \n
<?php \n\$OSList = array ( \n 'Windows 3.11' => 'Win16', \n'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)', \n'Windows 98' => '(Windows 98)|(Win98)|(Windows NT 4.10.2222)', \n'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)|(Windows NT 5.0.3700.6690)', \n'Windows XP' => '(Windows NT 5.1)|(Windows XP)', \n 'Windows XP 64-bit Edition 2003' => '(Windows NT 5.2.3790)', \n 'Windows Server 2003' => '(Windows NT 5.2)|(Windows NT 5.2.3790)', \n'Windows Vista' => '(Windows NT 6.0)|(Windows NT6.0.6000)', \n 'Windows 7' => '(Windows NT 7.0)', \n'Windows Home Server' => '(Windows NT 5.2.4500)', \n 'Windows Server 2008' => '(Windows NT 6.0.6001)|(Windows NT 6.0+)', \n 'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)', \n'Windows ME' => '(Windows ME)|(NT 4.90.3000)', \n 'Windows Millenium' => '(Windows NT 4.90)', \n 'Open BSD' => 'OpenBSD', \n'Sun OS' => 'SunOS', \n 'Sun OS' => 'SunOS', \n 'Linux' => '(Linux)|(X11)', \n 'Mac OS' => '(Mac_PowerPC)|(Macintosh)', \n 'QNX' => 'QNX', 'BeOS' => 'BeOS', 'OS/2' => 'OS/2', \n 'Search Bot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Sl urp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)' \n ); \nforeach($OSList as $CurrOS=>$Match){ \nif (eregi(\$Match, \$_SERVER['HTTP_USER_AGENT'])){ \n break;}} \n\$versi=ObtenerNavegador(); \n?> \n
<?php\nfunction getRealIP()\n{\nif( \$_SERVER['HTTP_X_FORWARDED_FOR'] != '' )\n{\n\$client_ip =\n(!empty(\$_SERVER['REMOTE_ADDR']))? \n\$_SERVER['REMOTE_ADDR'] \n: \n ((!empty(\$_ENV\['REMOTE_ADDR']) ) ? \n\$_ENV['REMOTE_ADDR'] \n: \n\"unknown\"); \n\$entries = split('[, ]', \$_SERVER['HTTP_X_FORWARDED_FOR']); \n\reset(\$entries); \n while (list(, \$entry) = each(\$entries)) \n{\n\$entry = trim(\$entry);\nif ( preg_match(\"/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/\",\$entry,\$ip_list))\n{ \n// http://www.faqs.org/rfcs/rfc1918.html \n\$private_ip = array(\n'/^0\./', \n'/^127\.0\.0\.1/',\n'/^192\.168\..*/',\n'/^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..*/', \n'/^10\..*/'); \n\$found_ip = preg_replace(\$private_ip, \$client_ip, \$ip_list[1]); \nif (\$client_ip != \$found_ip) \n{ \n\$client_ip = \$found_ip; \nbreak; \n}\n}\n}\n} \nelse \n{ \n\$client_ip = \n( !empty(\$_SERVER['REMOTE_ADDR']) ) ? \n\$_SERVER['REMOTE_ADDR'] \n:\n( ( !empty(\$_ENV['REMOTE_ADDR']) ) ? \n\$_ENV['REMOTE_ADDR'] \n: \n\"unknown\" ); \n} \n return \$client_ip; \n} \n\$actor= \""
.$rowEmp['id']."\"; \n\$ip=getRealIP(); \n\$consulta=\"".$Asunto."\"; \n\$dbh=mysql_connect (\"localhost\", \"".$Varusu."\", \"".$Varpass."\"); \nmysql_select_db (\"".$Vardb."\"); \n\$sql = \"INSERT INTO ".$Vartable." (actor, ip, consulta) \"; \n\$sql .= \"VALUES ('\$actor', '\$ip', '\$consulta')\"; \n\$result = mysql_query(\$sql); \n?>";
    
fwrite($gestor,$str);
    
fclose($gestor);
    for(
$i=1;$i<=$totEmp;$i++){
        if (
rename("$archivo""C:/Sitios/$Var/$Carpeta/$Nomar$i.php")) {
            print(
"Error en el proceso de renombrado\n");
        }else{
            print 
"Fichero renombrado con exito";
        }
    }
}
?>
</body>
</html>
Y una pregunta... para que tienes esto:
Código PHP:
if ($totEmp0
Porque al parecer si hay algo hace la linea que viene, pero como no tiene llaves, no supe si habia que cerrar un poco o todo, por eso hago la pregunta.

Prueba el codigo y si te sale algun error, lo posteas para ir viendo de que manera llegamos a solucionarlo.

Suerte!
__________________
El que dice "Solo sé que nada sé", esta asumiendo que sabe algo.
Lea las FAQ's!