Generate image using PHP for directory

0

Sorry if it got too strange the question, I have a system that when the user upload has no image it puts in the following img directory:

/xxxx/estatico/comuns/sem_imagem/

My idea was to generate an index.php in this directory that generated the image, is this method correct, or would it use server resources in vain? I have an average of 2000 hits per day.

    
asked by anonymous 27.02.2018 / 15:10

1 answer

1

Here is a very general example of what you want to do

Well you can create a function

Suppose you are receiving your upload data via $ _POST

function QualImagemUsar(){
   if(isset($_POST['variaveldaImage']){
        $caminhoDaImagem = "pasta/imagensUsuarios/iamgemQueUsarioEnviouEVcSalvou.jpg";
   }else{
        $caminhoDaImagem = "pasta/imagensUsuarios/imagemGenerica.jpg";
   }
   return $caminhoDaImagem ;
}

In your html

<img src="<?php echo QualImagemUsar(); ?>">

I think it's what you want a function that verifies if the image was sent or if you want to check if the image exists in the directory use if(file_exists("diretori/arquivo.jpg")

    
27.02.2018 / 16:11