2

I'm trying to echo out an image in a PHP function using 'img src', but I can't get it to work. The function itself works fine, everything else that I return or echo is working.

The image is located 1 folder 'back / up', then into the folder 'images' and the name of the image I'd like to acces in the 'images' folder is 'nike1.jpg'.

The following code isn't working:

echo '<img src="../images/nike1.jpg">';

No idea what I'm doing wrong here. Thanks in advance!

9
  • If the image is located in backup then it should be echo '<img src="../backup/images/nike1.jpg">'; Commented May 26, 2015 at 10:23
  • @YogeshPawar I think back / up refers to the parent directory. Commented May 26, 2015 at 10:24
  • write exact image path and your file path Commented May 26, 2015 at 10:24
  • you can check by putting the path like echo '<img src="/images/nike1.jpg">'; Commented May 26, 2015 at 10:25
  • You can check in the network tab of your developer tools in the browser which path is being loaded instead. Commented May 26, 2015 at 10:27

3 Answers 3

1

Its because your image files don't have proper read permission, make sure those image files are readable.If you are an Linux user type the bellow command which will provide all access to the file.

First go to the image file directory in terminal and type the following.

sudo chmod 777 *
Sign up to request clarification or add additional context in comments.

1 Comment

read permissions may be the problem, but I am hard pressed to think of the situation in which you can justify giving full access to a directory for everyone. That is a crazy security issue even in a supposedly image only directory (security.stackexchange.com/questions/8113/…). just do it right and set reasonable permissions for the account that is going to access the directory.
0

You need to check your path. I am little confused that you have "back" and "up" as two different folders or its one folder. It should be like "/your_parent_directory/back/up/images/nike1.jpg" or you can also write as "../back/up/images/nike1.jpg" if back and up are two folders. Can you tell the full path of the image.

1 Comment

Sorry, what I meant with 'back / up' is going on level 'back' in the file structure, hence the '../'
0

Not a real answer, but I decided to upload the image(s) on imgur and just use the image URL. Thanks for all the support.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.