Welcome Guest, Not a member yet? Register   Sign In
[solved] Upload file but don't save it.
#1

[eluser]Ñuño Martínez[/eluser]
Hi people.

I'm working with a controler that process a file uploaded by the user. The file will not be stored at the server, it will be loaded and processed. I know I can use the file uploading class, store the file on a temporary place, open it, load it, process it and delete it. The key here is the file would be pretty big so if I can access directly to the $_FILE['_name_']['tmp_name'] file and avoid the "temporary storage" I think it will be much faster and efficient.

Is there a way to do that?
#2

[eluser]pistolPete[/eluser]
Quote:if I can access directly to the $_FILE[‘_name_’][‘tmp_name’]
Why don't you do so using plain PHP?

If you want to use the upload class you'd have to extend it not to move the uploaded temp file.
You can access the temp file using:
Code:
$this->upload->file_temp
#3

[eluser]xwero[/eluser]
And it's not a good idea to process the temporary file because it lives in a directory that gets cleaned if the maximum limit for that directory is reached. This means at some point files will get lost instead of a warning you get when you run out of disk space.
#4

[eluser]Ñuño Martínez[/eluser]
[quote author="pistolPete" date="1236275205"]Why don't you do so using plain PHP?[/quote] I tried this:
Code:
if (isset ($_FILE))
    if (is_uploaded_file ($_FILE['archivo_csv']['tmp_name'])) {
      echo "<pre>".file_get_contents ($_FILE['archivo_csv']['tmp_name']).
           "</pre>";
      return;
    }
# Else loads form.
  $this->load->view ('upload_file_form');
It never shows the file content, always shows the form. May be I should configure CI or something.
#5

[eluser]Ñuño Martínez[/eluser]
[quote author="xwero" date="1236275406"]And it's not a good idea to process the temporary file because it lives in a directory that gets cleaned if the maximum limit for that directory is reached. This means at some point files will get lost instead of a warning you get when you run out of disk space.[/quote]PHP's help says <i>"The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed"</i>. I think it's enough, isn't it?.
#6

[eluser]pistolPete[/eluser]
Did you load the upload class?
Is your upload field called "archivo_csv" ?

Try this for debugging:
Code:
echo '<pre>'.print_r($_FILE,TRUE).'</pre>';
#7

[eluser]xwero[/eluser]
it's $_FILES not $_FILE
#8

[eluser]Ñuño Martínez[/eluser]
I'd find a mistake. I used "$_FILE" and should be "$_FILES" (thanks xwero). Now I fixed that but didn't work. The form is:
Code:
&lt;form action="/archivo_csv_seur" method="post"
  enctype="multipart/form-data"&gt;
  <label for="archivo_csv">Seleccione el archivo a subir:</label>
  &lt;input id="archivo_csv" type="file" class="input a250" /&gt;
  <br />
  &lt;input type="submit" /&gt;
&lt;/form&gt;

The controler code is:
Code:
echo '<pre>'.print_r ($_FILES, true).'</pre>';
  if (isset ($_FILES['archivo_csv']))
    if (is_uploaded_file ($_FILES['archivo_csv']['tmp_name'])) {
      echo "<pre>".file_get_contents ($_FILES['archivo_csv']['tmp_name'])."</pre>";
      return;
    }
# Carga el formulario y lo devuelve.
  $this->load->view ('administracion_archivo_csv_seur');

The first "echo" allways returns an empty array.
#9

[eluser]pistolPete[/eluser]
Code:
&lt;input id="archivo_csv" type="file" class="input a250" /&gt;
Your input only has an id but no name.
#10

[eluser]Yman[/eluser]
hi guys,

if i use

Code:
$this->upload->file_temp

do i have to define "upload_path" as well?




Theme © iAndrew 2016 - Forum software by © MyBB