Trouble with my readdir() script
Posted: Fri Oct 27, 2006 11:39 pm
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:
Here is my form handle script:
Here is my file display script:
Can someone tell me what my problem is? Thanks!
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:
<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>";
}
?>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!";
}
}
?>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!