Page 1 of 1

Trouble with my readdir() script

Posted: Fri Oct 27, 2006 11:39 pm
by kristie380
Ok so I am trying to read images that I have uploaded into a new directory. But all I'm getting are boxes with x's in them and not the pics I uploaded. When I click on properties on the boxes, it shows the correct path to the picture. It's just not showing the picture. If I try to go to the picture in my browser, it says I don't have permission to view the file. But I can see the picture in my FTP server. I'm trying to figure out if it is my script that is my problem or something else.

Here is my file upload script:

Code: Select all

<?php
$dbHost = 'mysql';
$dbUser = 'user';
$dbPass = 'pass';
$dbname = 'database';

$db = mysql_connect($dbHost,$dbUser,$dbPass);
$db_selected = mysql_select_db($dbname,$db);
if (!$db_selected) { die('Error : ' . mysql_error()); }

$sql = "SELECT * FROM `signup` WHERE id LIKE '%".$id."%' LIMIT 1"; 
$result = mysql_query($sql,$db); 

while ($newArray = mysql_fetch_array($result)) 
{ 

$id = $newArray['id'];


echo "<form method=\"POST\" action=\"submitphoto.php\" onsubmit=\"return FrontPage_Form1_Validator(this)\" language=\"JavaScript\" name=\"FrontPage_Form1\" enctype=\"multipart/form-data\">
			
			<table>
			<input type=\"hidden\" name=\"id\" value=\"$id\">
			<p><font color=\"#FF0000\"><b>Your Photo:&nbsp;
			<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"10000000\"><input type=\"file\" name=\"photo\" size=\"20\"></font></p>
			<p><input type=\"submit\" value=\"Submit Photo\" name=\"Submit\"></p>
		</form>
		</td>
	</tr>
</table>";
}
?>
Here is my form handle script:

Code: Select all

<?php
   
mkdir("$_POST[id]", 0775);	
	
$file_dir = "/$_POST[id]/";
foreach($_FILES as $file_name => $file_array) {

echo "<font color=\"#000033\" size=\"4\"><p>Thank you for submitting your photo!</p></font>";
echo "<p><b>Photo information:</b><br>";

echo "path: ".$file_array['tmp_name']."<br>\n";
echo "name: ".$file_array['name']."<br>\n";
echo "type: ".$file_array['type']."<br>\n";
echo "size: ".$file_array['size']."</p>\n";

if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'],
	"$file_dir/$file_array[name]") or die ("Couldn't copy");
	echo "Your file was uploaded successfully!";

}
}
?>
Here is my file display script:

Code: Select all

$dirname = "$id";
	  $dh = opendir($dirname) or die("couldn't open directory");
		  while ($file = readdir($dh)) {
		  		echo "<img src=\"$dirname/$file\"><br>";
				}
				  closedir($dh);

Can someone tell me what my problem is? Thanks!

Posted: Fri Oct 27, 2006 11:48 pm
by feyd
Without seeing the exact error you are apparently getting, I will guess that your web server doesn't run under the same user/permissions that your FTP account has, thereby creating the rift between file listings.

Posted: Sat Oct 28, 2006 1:18 pm
by wyrmmage
or you have some programming running on your web-server that blocks direct inking to images and is somehow blocking your image requests also...I had this problem awhile back, but I can't remember how I solved it, sry :(
One thing that I would recommend you do to speed up your echo"" statements:
Instead of using echo"" use echo('') or echo''
if you use two parentheses with echo, then you must escape all other double parentheses, but if you use one, you could re-write your code like this:

Code: Select all

echo ('<form method="POST" action="submitphoto.php" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1" enctype="multipart/form-data"> 
                        
                        <table> 
                        <input type="hidden" name="id" value="' . $id . '"> 
                        <p><font color="#FF0000"><b>Your Photo:&nbsp; 
                        <input type="hidden" name="MAX_FILE_SIZE" value="10000000"><input type="file" name="photo" size="20"></font></p> 
                        <p><input type="submit" value="Submit Photo" name="Submit"></p> 
                </form> 
');
Sorry I couldn't answer the question, but I hope the echo('') code helps you out a bit :)

-wyrmmage

Posted: Mon Oct 30, 2006 11:26 am
by kristie380
thanks for the advice on the echo statements!

am still not able to get my images to show up so any other tips would be greatly appreciated. Thanks!