Doubt - Php with file iput

Asked

Viewed 26 times

0

Good afternoon,

I have a form in which an image is uploaded, when it is uploaded I receive the photo as array below, in php it creates a temporary file in the case tmp_name.

I need to show the photo of this temporary file, because the form is invalidated so the image is still on tmp_name, that is shows the photo saved in this temporary file, and my doubt is how I access this temporary file showing the image ?

I already tried to do tpm_name concatenating with name tmp_name . / . name, however it does not bring this is my question which way to consume this temporary file is possible?

'foto' => array(
        'name' => 'brasao_1548090804.jpg',
        'type' => 'image/jpeg',
        'tmp_name' => 'C:\xampp\tmp\phpAAF9.tmp',
        'error' => (int) 0,
        'size' => (int) 74954
)
  • To display the file, you first need to move it to a publicly accessible location. The temporary directory is not public

  • it worked out vlw...

  • You say this to save the image file or to show at the same time the user inserts the input?

1 answer

0

Expected objective: when the user uploads an image and Submit in the form the image some of the input and the user needs to upload again.

What has been done.

I created a new temporary folder CONDUTOR_TEMP and when uploaded to input I moved the photo to a temporary directory and if there was validation in the form I consume the image sent to the temporary directory:

move_uploaded_file($['foto']['tmp_name'], **CONDUTOR_TEMP** . DS . $['foto']['name']);

After that moved I copy the image and play it in the original folder

copy(CONDUTOR_TEMP . DS . $['foto_visualizacao'], CONDUTOR . DS . $['foto_visualizacao']);

Final code:

$condutorFoto = $this->request->data['Condutor']['foto'];
            if (!empty($condutorFoto) && !empty($this->request->data['Condutor']['foto']['tmp_name'])) {
                if($this->request->data['Condutor']['foto_movida'] != 'Sim'){
                    move_uploaded_file($this->request->data['Condutor']['foto']['tmp_name'], CONDUTOR_TEMP . DS . $this->request->data['Condutor']['foto']['name']);
                    copy(CONDUTOR_TEMP . DS . $this->request->data['Condutor']['foto']['name'], CONDUTOR . DS . $this->request->data['Condutor']['foto']['name']);
                  
                    $this->request->data['Condutor']['foto_visualizacao']  = $this->request->data['Condutor']['foto']['name'];
                    $this->request->data['Condutor']['foto_movida'] = 'Sim';
                }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.