-2

I would like to know how to create a new url for each file upload. When people upload videos on the site, I would like the video to have its own url like this: "localhost/example.com/string". For example, Youtube has a new url for each upload like this "https://www.youtube.com/watch?v=209fsloiwifo" Is there a way for me to create a new url for each new post in php?

slidejones55
  • 63
  • 1
  • 5

1 Answers1

0

These are just arguments forwarded through to the back-end. You can always get query parameters in PHP using $_GET.

With some simple server configuration (e.g. MultiViews on Apache httpd) this could work for a script called watch.php and the $_GET param of "v" being "209fsloiwifo".

If you're just getting started with PHP and want to build applications, I'd also strongly recommend looking at various development frameworks to see if you can find one that fits your style and needs. They come in various flavors from lightweight like Fat-Free Framework to far more comprehensive like Laravel.

These give you concrete examples to work from and much stronger guidance on how to write your code and organize your files.

They also provide a routing layer that can make it easy to create clean, user-friendly URLs that communicate what they're doing without exposing the construction specifics of your site to the user.

In this case /watch would go through to a controller of some sort and render out the appropriate view with data loaded in from that v parameter as necessary.

A routing layer can also have parameters embedded transparently in the URL, such as in:

https://twitter.com/StackOverflow/status/1098612856990380034

Where StackOverflow and 1098612856990380034 are both parameters here, as in:

/:name/status/:id

Though the way these are described varies from framework to framework.

tadman
  • 194,930
  • 21
  • 217
  • 240
  • Hello, I created my own string through a function. Once the string is created, I add it to the original domain, "localhost/example.com/video/string". Is that ok for it to work? – slidejones55 Feb 26 '19 at 03:03
  • Why do you have both "localhost" and "example.com" in the URL? I'd strongly suggest looking at frameworks to see how their routing layer works. Most can do exactly what you want out of the box. – tadman Feb 26 '19 at 16:11