Home > Software design >  How should i save photos with php/apache?
How should i save photos with php/apache?

Time:12-30

My question is, where should i save photos that will be uploaded from the users? my root dir for the server is C:/apache here i have the folder that contains the php files C:/apache/htdocs . I was wondering where should i save the files, i heard it will be better if i saved it somewhere else than the htdocs (folder that contains the php scripts), but here is the thing. If i save it directly to C:/apache then i can't access the photos. While saving it to a new folder in C:/apache/htdocs/photos would make the photos folder visible or accesible from the php pages. Is there a way i can save them somewhere else, like, let's say one folder up from the htdocs folder?

EDIT: the .htaccess seems like a good solution. Though i'm curious about this 1 thing: I was thinking, is it possible to have directories something like this?

--->phpfiles           
    |--->index.php       
    |--->another.php   
--->photos    
    |--->1.jpg       
    |--->etc.jpg 

And still somehow link those photos to my php files? Like making the server only view the phpfiles folder for links and all of that (so i can go to localhost/index.php and not localhost/phpfiles/index.php ) ?

EDIT 2: My server root is C:/apache, while my Document Root is C:/apache/htdocs. in case of any misunderstanding, sorry

CodePudding user response:

I would suggest putting the uploads in a folder like you suggested with C:/apache/htdocs/photos and place a .htaccess in that file that prevents direct access to the folder. That way the folder won't be visible and they can't access the images without the file name.

Another solution would be to upload the images on a third party server.

  • Related