Julien_he
Julien_he

Reputation: 165

Localhost subfolder PHP

I have a problem with my localhost website.

So I explain here my problem, I have a folder in localhost/sg/ with all php file. If i want to show a picture I should use /sg/upload/myfile.jpg for example.

But If I upload my php file on my server that's doesn't work, because I don't have a /sg/ folder in my www folder.

So my question is, it's possible to have a script who can manage this for offline and online?

If you have question, don't hesitate.

Thank you.

Upvotes: 2

Views: 2090

Answers (5)

hakre
hakre

Reputation: 198119

Typically only the basedir differs, but not the site structure:

development: http://localhost/project-blue/

production:  http://project-blue.example.com/

In that directory you place a PHP file, let's say index.php:

http://localhost/project-blue/index.php

If it should display a URL to an uploaded picture called upload/picture.jpg, you only need to link it properly:

<img src="upload/picture.jpg">

Which will then make the browser obtain this this URL:

 http://localhost/project-blue/upload/picture.jpg

That will work on both, development and production:

 http://project-blue.example.com/upload/picture.jpg

So actually there is not much you need to care about here.

Upvotes: 0

somnath
somnath

Reputation: 1335

Cant you also upload the image folder /sg/upload/ to your production server? When publishing programs, the dependencies also need to be published. In your case, that folder is your project's dependency. EIther you need to use config files like John has suggested to specify the different upload folder for production environment or you need to simply upload that folder as well.

Upvotes: 0

John
John

Reputation: 2501

set upload path relative to your site path for example define a constant:

offline:

<?php
define ("SITEPATH","http://localhost/sg/upload/");
<?

online:

<?php
define ("SITEPATH","http://www.yoursite.com/upload/");
<?

then use this constant (SITEPATH) to locate the file upload destination

<?php
$destination = SITEPATH.$filename;
?>

Upvotes: 2

Amarnasan
Amarnasan

Reputation: 15549

I think your problem is more related to your web server (Apache?) than PHP.

I guess the answer to your problem is a proper configuration in your (Apache?) files, more specifically with the DocumentRoot directive both in production and developing servers

Upvotes: 0

John Conde
John Conde

Reputation: 219874

You could use a config file that sets the path for your images, and other files, dynamically depending on whether the site is local or on production.

Upvotes: 2

Related Questions