I’m using a form to upload files into a specific upload folder.
Now, in my local development environment, the local folder is harcoded in a variable like this
$destination = 'c:/public_html/discography/artwork/';
Once the script is completed and ready to be moved in the live environment, the upload folder will be
$destination = '/home/my_name/public_html/discography/artwork/';
My question is the following:
Right now, both variables are hard coded. How do i make it so depending on the environment, the correct path is selected?
If possible, i’d like it to be in a define statement, so i can use it anywhere in my script:
define('UPLOAD_ARTWORK', ????);
local:
$destination = 'c:/public_html/discography/artwork/';
$move = move_uploaded_file($_FILES['artwork']['tmp_name'], $destination.$_FILES['artwork']['name']);
live:
$destination = '/home/my_name/public_html/discography/artwork/';
$move = move_uploaded_file($_FILES['artwork']['tmp_name'], $destination.$_FILES['artwork']['name']);
wishing for
define('UPLOAD_ARTWORK', ????);
$move = move_uploaded_file($_FILES['artwork']['tmp_name'], UPLOAD_ARTWORK.$_FILES['artwork']['name']);
Thanks
Your on the right path. All you need is some way to determine whether the script is being run locally or on the live server. This could be a subdomain if you’re using something like dev.example.com or an ip address ala 127.0.0.1. Then you could write it like this.