atticus Posted November 1, 2007 Share Posted November 1, 2007 I am uploading images to a server and saving the script location to a mysql database. It is loading into the server. When I call it with PHP it doesn't show up. When I try to access it directly I get a an error stating that this directory is restricted without an index file. I added an index file, but it made no difference. The directory is set to 777. Also, I manually changed the chmod on the image to 777 and now I am getting a "page not found" error. here is the upload code: <form method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> <?php $db_host = "xxxxxx"; $db_user = "xxxxx"; $db_pwd = "xxxxx"; $db_name = "comment"; $uploadDir = 'upload/'; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $query = "INSERT INTO upload2 (name, size, type, path ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); echo "<br>Files uploaded<br>"; } ?> Here is the display code: <?php $db_host = "xxxxxx"; $db_user = "xxxxx"; $db_pwd = "xxxxx"; $db_name = "comment"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> <img src="banner-top.gif"/> <table> <?php $sql = "SELECT * FROM upload2"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo "<tr>"; echo "<td>".$row['userfile']."</td>"; echo "<td><img src=".$row['path']."/></td>"; echo "</tr>"; } ?> I can't seem to find the problem. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/ Share on other sites More sharing options...
holladb Posted November 1, 2007 Share Posted November 1, 2007 mysql_select_db($db_name) or die(mysql_error()); $results = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($results) or die(mysql_error()); try that in place of $query = mysql_query($sql); while($row = mysql_fetch_array($query)) Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382929 Share on other sites More sharing options...
atticus Posted November 1, 2007 Author Share Posted November 1, 2007 mysql_select_db($db_name) or die(mysql_error()); $results = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($results) or die(mysql_error()); Thanks for the tip, however I am still getting the same problem with no error from mysql. Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382930 Share on other sites More sharing options...
holladb Posted November 1, 2007 Share Posted November 1, 2007 try chmoding to 775 rather than 777. I have found in various cases this works for me. It could also be an issue with the server security. If you're set to something like 3.1 security that can be a big change from high security. Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382932 Share on other sites More sharing options...
atticus Posted November 1, 2007 Author Share Posted November 1, 2007 try chmoding to 775 rather than 777. I have found in various cases this works for me. It could also be an issue with the server security. If you're set to something like 3.1 security that can be a big change from high security. I changed the directory to 775 and had to change each photo to 775 to be able to view them be typing in http://site/directory, however I am still not able to call the images with PHP into the index page. Also, how can I make sure the image is uploaded as a 775? Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382938 Share on other sites More sharing options...
atticus Posted November 1, 2007 Author Share Posted November 1, 2007 The path was corrupted due to the fact it was adding "/" to the end of the path: [code=php:0] echo "<td><img src=".$row['path']."/></td>"; [/code] Resulting in: http://site.com/directory/image.jpg/ I removed the slash for now and it is working perfectly How do you include the "/" in the "<img />" tag to keep it xhtml strict? thanks for everybody's help Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382941 Share on other sites More sharing options...
holladb Posted November 1, 2007 Share Posted November 1, 2007 if you changed the directory as 755 it should just go in as 755. Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382942 Share on other sites More sharing options...
atticus Posted November 1, 2007 Author Share Posted November 1, 2007 if you changed the directory as 755 it should just go in as 755. I did change the directory to 755 but the images are going in as 600 ??? Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382948 Share on other sites More sharing options...
holladb Posted November 1, 2007 Share Posted November 1, 2007 chmod($filePath, 0755); try adding this to your upload script. Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382962 Share on other sites More sharing options...
atticus Posted November 1, 2007 Author Share Posted November 1, 2007 chmod($filePath, 0755); try adding this to your upload script. it is still going in as a 600 Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382973 Share on other sites More sharing options...
holladb Posted November 1, 2007 Share Posted November 1, 2007 is $filePath defining the actual file??? show me where you entered the chmod code Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382979 Share on other sites More sharing options...
atticus Posted November 1, 2007 Author Share Posted November 1, 2007 if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); chmod($filePath, 0755); if (!$result) { echo "Error uploading file"; exit; } if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $query = "INSERT INTO upload2 (name, size, type, path ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); include '../library/closedb.php'; echo "<br>Files uploaded<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382985 Share on other sites More sharing options...
atticus Posted November 1, 2007 Author Share Posted November 1, 2007 how do I modify my original posting? Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-382990 Share on other sites More sharing options...
AndyB Posted November 1, 2007 Share Posted November 1, 2007 how do I modify my original posting? If it was removing the db info, that's done Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-383004 Share on other sites More sharing options...
holladb Posted November 1, 2007 Share Posted November 1, 2007 try adding the chmod code after your magic quotes dialog. this will get the true path if you're adding slashes. and there should be an edit button. Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-383005 Share on other sites More sharing options...
atticus Posted November 1, 2007 Author Share Posted November 1, 2007 how do I modify my original posting? If it was removing the db info, that's done thank you very much! Thanks to you holladb for pointing that out... Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-383007 Share on other sites More sharing options...
holladb Posted November 1, 2007 Share Posted November 1, 2007 not a problem, did you try the new chmod way?? Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-383011 Share on other sites More sharing options...
atticus Posted November 1, 2007 Author Share Posted November 1, 2007 yes I did...it did not work...however I cleared my cache, went back and tried it: $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); chmod($filePath, 0755); if (!$result) { echo "Error uploading file"; exit; } It worked great, thanks for your help, I really really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-383015 Share on other sites More sharing options...
atticus Posted November 1, 2007 Author Share Posted November 1, 2007 edit button? As in I need to add a modify/edit button? Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-383017 Share on other sites More sharing options...
holladb Posted November 1, 2007 Share Posted November 1, 2007 no no lol i was referring to editing your post, but edit/delete buttons are great tools for upload scripts! especially in the admin panel! check out what i did on my site, http://www.picstools.com Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-383023 Share on other sites More sharing options...
atticus Posted November 1, 2007 Author Share Posted November 1, 2007 very cool site, I signed up... Quote Link to comment https://forums.phpfreaks.com/topic/75673-solved-problem-displaying-images-with-php-and-mysql/#findComment-383039 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.