Generate image using PHP for directory

Asked

Viewed 60 times

0

Sorry if it got very 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 to generate the image, is this method correct or would it use server resources in vain? I have an average of 2000 accesses per day.

  • your question was left without context, you have an upload system, to which the if the user does not send the image, it will put without correct image? but in case every upload creates a directory on your server ? and you want to put an index.php file to create a copy of a standard image for that directory ?

  • Sorry, buddy, here’s the deal. I have a right upload , in this upload I have some data that the user should insert , in this case not all are required as the image , so every time there is an image the system puts in the img src this static directory . I’d like to know if putting an index.php there is the right way to generate an image to stay in place, you know?

  • Right now I understood, I will post an answer

  • Well in case you do not need to create an image every time the user n send aimage and nor apotar to several directories just check if aimage was sent otherwise apota the image to another fixed directory

  • is because this is a default system configuration and there are already many uploads like this would have like me to do so?

1 answer

1

Here’s an example of what you want to do

Good 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 believe it is what you want a function that would serve if the image was sent or if you want to check if there is an image in the directory use the if(file_exists("diretori/arquivo.jpg")

Browser other questions tagged

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