Foros del Web » Creando para Internet » Herramientas y Software »

Subir un archivo por url en vez de por formulario.

Estas en el tema de Subir un archivo por url en vez de por formulario. en el foro de Herramientas y Software en Foros del Web. Actualmente subo la lista de productos en la base de datos con el formulario. La pregunta es ¿que tengo que cambiar en el código para ...
  #1 (permalink)  
Antiguo 04/02/2015, 05:44
 
Fecha de Ingreso: febrero-2015
Mensajes: 1
Antigüedad: 9 años, 2 meses
Puntos: 0
Subir un archivo por url en vez de por formulario.

Actualmente subo la lista de productos en la base de datos con el formulario.

La pregunta es ¿que tengo que cambiar en el código para subir los ficheros desde una URL?

Ejmplo
dominio.com/admin/easypopulate.php?url=listadeprecios.txt


ESTE ES EL FORMULARIO
<table width="75%" border="2">
<tr>
<td width="75%">
<FORM ENCTYPE="multipart/form-data" ACTION="easypopulate.php?split=0" METHOD=POST>
<p>
<div align = "left">
<p><b>Subir Catalogo a la base de datos</b></p>
<p>
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="100000000">
<p></p>
<input name="usrfl" type="file" size="50">
<input type="submit" name="buttoninsert" value="Insertar en BD">
<br>
</p>
</div>

</form>



ESTE ES EL CODIGO QUE SUBE Y EJECUTA EL ARCHIVO
-------------------------------------------------------------------------
<?php
$usrfl_name = $HTTP_POST_FILES['usrfl']['name'];
$usrfl_size = $HTTP_POST_FILES['usrfl']['size'];
$usrfl = $HTTP_POST_FILES['usrfl']['tmp_name'];
if ($localfile or (is_uploaded_file($usrfl) && $split==0)) {
//*******************************
//*******************************
// UPLOAD AND INSERT FILE
//*******************************
//*******************************

if ($usrfl){
// move the file to where we can work with it
$file = tep_get_uploaded_file('usrfl');
if (is_uploaded_file($file['tmp_name'])) {
tep_copy_uploaded_file($file, DIR_FS_DOCUMENT_ROOT . $tempdir);
}

echo "<p class=smallText>";
echo "File uploaded. <br>";
echo "Temporary filename: " . $usrfl . "<br>";
echo "User filename: " . $usrfl_name . "<br>";
echo "Size: " . $usrfl_size . "<br>";

// get the entire file into an array
$readed = file(DIR_FS_DOCUMENT_ROOT . $tempdir . $usrfl_name);
}
if ($localfile){
// move the file to where we can work with it
$file = tep_get_uploaded_file('usrfl'); $attribute_options_query = "select distinct products_options_id from " . TABLE_PRODUCTS_OPTIONS . " order by products_options_id";

$attribute_options_values = tep_db_query($attribute_options_query);

$attribute_options_count = 1;
//while ($attribute_options = tep_db_fetch_array($attribute_options_values)){
if (is_uploaded_file($file['tmp_name'])) {
tep_copy_uploaded_file($file, DIR_FS_DOCUMENT_ROOT . $tempdir);
}

echo "<p class=smallText>";
echo "Filename: " . $localfile . "<br>";

// get the entire file into an array
$readed = file(DIR_FS_DOCUMENT_ROOT . $tempdir . $localfile);
}

// now we string the entire thing together in case there were carriage returns in the data
$newreaded = "";
foreach ($readed as $read){
$newreaded .= $read;
}

// now newreaded has the entire file together without the carriage returns.
// if for some reason excel put qoutes around our EOREOR, remove them then split into rows
$newreaded = str_replace('"EOREOR"', 'EOREOR', $newreaded);
$readed = explode( $separator . 'EOREOR',$newreaded);


// Now we'll populate the filelayout based on the header row.
$theheaders_array = explode( $separator, $readed[0] ); // explode the first row, it will be our filelayout
$lll = 0;
$filelayout = array();
foreach( $theheaders_array as $header ){
$cleanheader = str_replace( '"', '', $header);
// echo "Fileheader was $header<br><br><br>";
$filelayout[ $cleanheader ] = $lll++; //
}
unset($readed[0]); // we don't want to process the headers with the data

// now we've got the array broken into parts by the expicit end-of-row marker.
array_walk($readed, 'walk');

}

if (is_uploaded_file($usrfl) && $split==1) {
//*******************************
//*******************************
// UPLOAD AND SPLIT FILE
//*******************************
//*******************************
// move the file to where we can work with it
$file = tep_get_uploaded_file('usrfl');
//echo "Trying to move file...";
if (is_uploaded_file($file['tmp_name'])) {
tep_copy_uploaded_file($file, DIR_FS_DOCUMENT_ROOT . $tempdir);
}

$infp = fopen(DIR_FS_DOCUMENT_ROOT . $tempdir . $usrfl_name, "r");

//toprow has the field headers
$toprow = fgets($infp,32768);

$filecount = 1;

echo "Creating file EP_Split" . $filecount . ".txt ... ";
$tmpfname = DIR_FS_DOCUMENT_ROOT . $tempdir . "EP_Split" . $filecount . ".txt";
$fp = fopen( $tmpfname, "w+");
fwrite($fp, $toprow);

$linecount = 0;
$line = fgets($infp,32768);
while ($line){
// walking the entire file one row at a time
// but a line is not necessarily a complete row, we need to split on rows that have "EOREOR" at the end
$line = str_replace('"EOREOR"', 'EOREOR', $line);
fwrite($fp, $line);
if (strpos($line, 'EOREOR')){
// we found the end of a line of data, store it
$linecount++; // increment our line counter
if ($linecount >= $maxrecs){
echo "Added $linecount records and closing file... <Br>";
$linecount = 0; // reset our line counter
// close the existing file and open another;
fclose($fp);
// increment filecount
$filecount++;
echo "Creating file EP_Split" . $filecount . ".txt ... ";
$tmpfname = DIR_FS_DOCUMENT_ROOT . $tempdir . "EP_Split" . $filecount . ".txt";
//Open next file name
$fp = fopen( $tmpfname, "w+");
fwrite($fp, $toprow);
}
}
$line=fgets($infp,32768);
}
echo "Added $linecount records and closing file...<br><br> ";
fclose($fp);
fclose($infp);

echo "You can download your split files in the Tools/Files under /catalog/temp/";

}
---------------------------------------------------------------------


Para llegar al archivo easypopulate.php
1º Entra en www.PatroCine.es
2º Descargar OsCommerce Empresa 3.0
La ruta del archivo es
/catalog231/admin/easypopulate.php

Etiquetas: text, url, vez
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 07:59.