PHP insert image upload url in database [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have two way for insert image upload url in MySQL database:
One:(only filename)
1410468094_shutterstock_130757219.jpg
Two:(full url)
http://localhost/nws/uploads/files/1/shutterstock_130757219.jpg
which way is better?

file name is best cause if anytime you change folder name or location .

Second way without the domain name is batter. I mean uploads/files/1/shutterstock_130757219.jpg is batter. Because your domain name may change over time. But you should put the file path relative to your web root directory.

If all images will be put in the same folder you would like to leave out the path, that way you could move the images one day to S3, CDN or anywhere else and won't have to update all the records. However if the images comes from all over the Internet, you need the full path.

Related

How can I share image between two websites? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Two websites are running on one server, so let's say it A.com and B.com. Their document root directory is different of course. The problem is when I upload image on A.com, I should show it on B.com too.
How can I solve this?
I don't want to link from one site to another. I should use image in generating PDF and link is not working.
Just use full path in your code!!! It must work or check permission.
Use the url's for both site example if u you need an file from a.com in b.com just call
a.com/your_file_path
Let me know if there is any confusion

How Should I store My User's Images? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I've been reviewing all sorts of ways and researching, but I haven't been able to find solutions. Should I store them in my host's database, my filesystem, or through a third party? If through a third party, which one? Imgur, AWS S3, etc?
The best way is to store the images' location on the database and then link it via PHP or ASP from some protected directory.
Example (when you are saving picture name and extension with extension):
Query to select all data:
PHP:
{ $profile_picture = $row['pictureLocation']; }
Then wrapping around the path to directory:
$profile_picture = "../assets/protected/images/users/" . $profile_picture ;
HTML:
<img src="<?php echo $profile_picture ; ?>" >
Usually the easiest way (space allowing) is to simply store the actual picture file in your filesystem. Then, in order to reference the file, store the file path in a MySQL database. With that said, there are many ways to store pictures and the best is to experiment with them.

twig best practice regarding template locations [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
My site isn't using a front controller pattern or anything fancy, it's currently a bunch of php files in folders.
e.g:
http://www.example.com/customer/account-settings.php
maps direcctly to:
/var/www/sites/example/http/customer/account-settings.php
I've started playing with twig, and wonder what the best practice for locating the template files is?
Should I put them all in
/var/www/sites/exammple/templates/
or should I put them alongside their corresponding .php file?
/var/www/sites/example/http/customer/account-settings.twig
/var/www/sites/example/http/index.twig
etc?
I would place all files in one directory and than create a configuration variable like
$templatesDir='/var/www/sites/exammple/templates/';
to reference the location.
That way views are organized and not scattered around the project. If for some reason you want to change their location to another directory you just have to change the $templatesDir variable in one place.

Storing a file into a database & uploading it in a webpage [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Background
I'm creating a website where the user can store an article as a file in the database and than upload the file's content into a page in the website using a form. The file may only contain text or image or both.
Question
Can anyone walk me through this?
I would suggest you to create a database table having fields having the userId, and path of the file.
The file uploaded should be saved in the Web Server, and its path need to be saved in the database.
The vice-versa should be done while retrieving the file content.

File upload validation - to unlink from tmp or not [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Just a quick question on best practice.
If my website visitors are uploading files that fail file validation (too large, wrong filetype etc.) is it safer/ more efficient to programatically delete the file from the servers tmp directory? Or do I just let the purge cycle performed by the server take care of it?
Many thanks
Phill
From the manual:
The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.
So, you could omit it, however:
Whatever the logic, you should either delete the file from the temporary directory or move it elsewhere.
... it's always nice to be explicit in your script. In short: you don't have to, but I would.

Categories