Page 1 of 1

I think I have a problem witih file permissions - [[SOLVED]]

Posted: Fri Nov 18, 2011 7:41 am
by jaswic
Hi,

I am pretty new to PHP. As a way to learn PHP and MySQL I am working on a database that will store filenames of images and attach tags to them. I would like to be able to search for a tag and see a list of images that have that tag. My plan is to display the thumbnails in an html table and them click the thumbnail to see the full image. In the long run, I am doing this for a church for them to be able to keep track of the images they use in their events and so I am working on some fairly dated hardware.

I have a Windows XP system that I am running a WAMP 2.2 server. I am up to date on all the windows updates. This is the information from the info script posted in the FAQs:

PHP Version: 5.3.8
Display Errors: On
Error Level: Not E_ALL
Register Globals: Off

OK, so here is my problem. I store the file name in the database. (I have tried to store either the full path or just the filenname, I get the same problem either way.) I do a query from my database to get the thumbnail filename. These are returned in a mysqli result object. Then I am doing a foreach loop to display the thumbnails. My goal is to do this in an html table. However, right now I can not display the images so I haven't even got to building the table yet.

My plan was to have a folder (e.g. c:\images) that had a folder for thumbnails and a folder for images. However, I could not display the images so I moved the folder to the root folder of the website. I still can not display the images.

Here is my code:

Code: Select all

<?php
	require_once ("common.inc.php");
?>

<html>
	<head></head>
	<title>Database test</title>
	<body>
		<h1>Image database</h1>
		<p>This is a test of how to show images from the database.</p>
		
		<?php
			$conn = new connection("images", myUserName, db_password, "localhost");
			$mysqli = $conn->connect();
			
			$thumbnail = new image();
			$result = $thumbnail->getAllThumbnails($mysqli);
			
			while ($row = $result->fetch_assoc()) { 
				printf('<img src="http://localhost/images/thumbs/%s" />', $row["thumb"] );
				echo $row["thumb"].'<br />';
				//echo '<img src="images\\thumbs\\'.$row["thumb"].'" /><br />';
			}
			
		?>
		<!-- try to access an image directly -->
		<img src="images/thumbs/tn_image1.jpg" />
	</body>

</html>


If I have the image in the root directory of the webpage, then the image will display e.g.:

Code: Select all

<img src="filename.jpg" />
but if I move the image into a lower folder, it does not display.

Code: Select all

<img src="images/filename.jpg" />
I assume this is because of file permissions so I made the image/thumbs and image/originals folders with a php script so that it would be the owner of them folders, but that did not help.

I am really stumped with this and I think it should be simple. Thanks in advance for the help.

Re: I think I have a problem witih file permissions

Posted: Sat Nov 19, 2011 4:04 am
by social_experiment

Code: Select all

printf('<img src="http://localhost/images/thumbs/%s" />', $row["thumb"] );
Have you tried using a relative path instead of an absolute one; images/thumbs/..... ?

Re: I think I have a problem witih file permissions

Posted: Sat Nov 19, 2011 6:15 am
by jaswic
Yes, I tried that too. In the code above you can see where I commented out a line that used relative paths. It was not working so I tried the "http:/:..." url instead.

Since this is running on a WinXP machine, I have tried both forward and backslashes. Each gives the same effect, which is nothing. The images will not load either way.

Re: I think I have a problem witih file permissions

Posted: Sat Nov 19, 2011 10:59 am
by social_experiment
http://www.webdeveloper.com/forum/archi ... 65933.html
Using backslashes won't work; Can you access the images directly via the browser, http://localhost/dir/images/image.jpg ; and are you receiving any error messages if you do?

Re: I think I have a problem witih file permissions

Posted: Sat Nov 19, 2011 11:57 am
by jaswic
I read the post about permissions. It deals with using chmod to set permissions on the directory. However, this is running on a Windows XP/WAMP combination. Windows does not acknowledge the chmod type settings like a linux box would.

I have an IIS server that I run at home. That system has an IUSR_SERVERNAME account that is used to allow anonymous access to webpages. I don't see any way to supply this sort of account in my WAMP system.

If I try to access the images directly by using "http://localhost/images/thumbs/tn_image1.jpg" then I get a HTTP 403 error.
Image

I can access the web page, and if I have the images located in the root directory (c:\wamp\www) then I can display the images. If I put them into a subfolder, they will not display.

When I used the backslashes, I properly escaped them in the strings. I still got the same errors. I used forward slashes and still get errors. You can see a result of my tests below:
Image

Re: I think I have a problem witih file permissions

Posted: Sun Nov 20, 2011 5:57 am
by social_experiment
jaswic wrote:I read the post about permissions. It deals with using chmod to set permissions on the directory. However, this is running on a Windows XP/WAMP combination. Windows does not acknowledge the chmod type settings like a linux box would.
Yes that's true.
http://support.microsoft.com/kb/308419
Here is something on setting permissions for files in windows.

If this still doesn't work (and it was me) i'd try reinstalling the WAMP and if that failed to solve the problem i'd upgrade to XAMPP.

Re: I think I have a problem witih file permissions

Posted: Sun Nov 20, 2011 12:13 pm
by jaswic
I read through the knowledge base articles from MS (thanks for the links, by the way). I did add an "anonymous logon" user group permission to those files but that did not help.

I also put just a "regular" html file in the subdirectory. That did not display at all. Your post above got me to thinking that the problem is a configuration error in my apache httpd.conf file. I think the <directory> defaults to block (DenyAll) all access to the subdirectories. Moving to XAMPP may not necessarily correct that setting.

I think I just need to learn how to properly configure my apache. Like I said before, I use IIS on my home server so I don't konw much about apache.

I will do some reading about apache and post an answer back here if I find out anything.

Re: I think I have a problem witih file permissions

Posted: Sun Nov 20, 2011 3:35 pm
by jaswic
I have fixed the issue though I don't know how I particularly that I did it.

I added an "allow from" directive to my apache httpd.conf file. I added both allow from 127.0.0.1 and also allow from localhost. I have not tried to acces the webpage from another computer on my network.

I was accessing the page from a specific URL. "http://localhost/database.php"

I have moved all the files to a subfolder (database) of my www root. Then I changed the name of database.php to index.php. Now I can access the page as "http://localhost/database/".

I also edit the line that I used to actually display the image. I commented out the "printf" line in the source above and un-commented the line that says

Code: Select all

   echo '<img src="images/thumbs/'.$row["thumb"].'" />';
So I don't know which change finally did it, but it works.

Unfortunately, I did not test which of these actually fixed it. I made several changes at once then it worked. If anyone is really interested, then I will go back and try to figure out what worked.

Thank you for your assistance.

Re: I think I have a problem witih file permissions - [[SOLV

Posted: Sun Nov 20, 2011 11:46 pm
by social_experiment
jaswic wrote:If anyone is really interested, then I will go back and try to figure out what worked.
If you have time to do this it could help someone in a similar situation somewhere along the line :)