Page 1 of 2
failed opendir / readdir
Posted: Thu Feb 05, 2004 2:22 pm
by ol4pr0
I will get straight to the point.
i got these errors from my script ..
Code: Select all
Warning: opendir(htdocs/tms/up/files/down/): failed to open dir: Invalid argument in C:\Apache2\htdocs\tms\up\download.php on line 25
Warning: readdir(): supplied argument is not a valid Directory resource in C:\Apache2\htdocs\tms\up\download.php on line 26
this is my php code
Code: Select all
$extlimit = "yes"; //Do you want to limit the extensions of files uploaded
$limitedext = array(".php",".jpg",".rar",".zip",".html",".exe"); //Extensions you want files uploaded limited to.
$sizelimit = "yes"; //Do you want a size limit, yes or no?
$sizebytes = "10000000"; //size limit in bytes
$dl = "http://localhost/tms/up/files/down/"; //url where files are uploaded
$absolute_path = "htdocs/tms/up/files/down/"; //Absolute path to where files are uploaded
$websiteurl = "http://localhost"; //Url to you website
$websitename = "http://localhost";
if (!isset($action)) {
$action = "900";
}
switch($action) {
default:
echo "
<html>
<head>
<title>File Download</title>
</head>
<body><a href=$websiteurl>Return to $websitename</a>";
$list = "<table width=700 border=1 bordercolor=#000000 style="border-collapse: collapse">";
$list .= "<tr><td width=700><center><b>Click To Download</b></center></td></tr>";
$dir = opendir($absolute_path);
while($file = readdir($dir)) {
if (($file != "..") and ($file != ".")) {
//Download files with spaces fix by Kokesh
$list .= "<tr><td width=700><a href='$dl/$file'>$file</a></center></td></tr>";
}
}
$list .= "</table>";
echo $list;
echo"
<br><br>
<a href=http://tms.com/>TMS</a>
</body>
</html>";
break;
}
I checked the directory its there
____________________-
Also i used to be able to use this
Its doesnt anymore..
Any suggustions?
Posted: Thu Feb 05, 2004 5:49 pm
by Pointybeard
You running your server on windows? If you are, i have found that you cant seem to use absolute paths per say, unless you do the full path like so:
c:/Apache2/htdocs/tms/up/files/down/
Im not sure if this is an apache config thing, or just a prob with using windows over unix. anway, Hope that helps
Posted: Thu Feb 05, 2004 6:01 pm
by ol4pr0
Weird thing i used this script a long time ago..
with Easyphp ( never with apache ) and yes on a windows machine
going to try it with linux ( or better say, it has to work with linux lol )
just using w2k for testing ..
C:\<-- tried that one.. no succes
Posted: Thu Feb 05, 2004 6:50 pm
by DuFF
Easiest way to get an absolute path would be:
Code: Select all
<?php
$absolute_path = $_SERVER['DOCUMENT_ROOT'] . "path/to/file/";
?>
Posted: Fri Feb 06, 2004 9:04 am
by ol4pr0
Hmm.. didnt do much for me
i also added a
To see if it would return something up in my logs..
However i do not have any errors in my logs concerning this script
Posted: Fri Feb 06, 2004 9:18 am
by devork
= is assignment operator
$var ='php'; // assign data "php" to variable $var
== is equality operator wheth things on both sides are equal
if ($var=="php") //returns true if same
!= is equality operator which returns true if the both sides are not same.
if ($var!="php") //returns true if not same
there is one another
=== which shows that data on the both side is of same type.
Posted: Fri Feb 06, 2004 9:41 am
by Illusionist
devork, what did that have to do with anything??
ol4pr0, post the code that your using
Posted: Fri Feb 06, 2004 9:41 am
by Illusionist
devork, i think you meant to post that
here!
Posted: Fri Feb 06, 2004 11:41 am
by ol4pr0
Here is the code ( had it cut out of all the html form <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>.. to make it somewhat more clearly
Code: Select all
<?
error_reporting(15);
if(!isset($upload)) {
$upload = "900";
}
switch($upload) {
default:
include "config.php";
echo "
<html>
<head>
<title>Upload</title>
// alot of html form jabiedabie hehe..
<tr>
<td bgcolor="#818EA0"><font size="2">The following restrictions apply:</font><ul type="square">
<li><font size="2">File extension must be <b>";
if (($extensions == "") or ($extensions == "") or ($ext_count == "0") or ($ext_count == "") or ($limit_ext != "yes") or ($limit_ext == "")) {
echo "any extension";
} else {
$ext_count2 = $ext_count+1;
for($counter=0; $counter<$ext_count; $counter++) {
echo " $extensions[$counter]";
}
}
if (($limit_size == "") or ($size_limit != "yes")) {
$limit_size = "any size";
} else {
$limit_size .= " bytes";
}
echo"</b></font></li>
<li><font size="2">Maximum file size is $limit_size</font></li>
<li><font size="2">No spaces in the filename</font></li>
<li><font size="2">Filename cannot contain illegal characters
(/,*,\,etc)</font><BR>
</li>
</ul>
<form method="POST" action="upload.php?upload=doupload" enctype="multipart/form-data">
<p align="center">
<input type=file name=file size=30 style="font-family: v; font-size: 10pt; color: #5E6A7B; border: 1px solid #5E6A7B; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1"><br>
// alot more of that html ..
</html>";
break;
case "doupload":
include "config.php";
$endresult = "<font size="2">File Was Uploaded</font>";
if ($file_name == "") {
$endresult = "<font size="2">No file selected</font>";
}
else{
if(file_exists("$absolute_path/$file_name")) {
$endresult = "<font size="2">File Already Existed</font>";
} else {
if (($size_limit == "yes") && ($limit_size < $file_size)) {
$endresult = "<font size="2">File was to big</font>";
} else {
$ext = strrchr($file_name,'.');
if (($limit_ext == "yes") && (!in_array($ext,$extensions))) {
$endresult = "<font size="2">File is wrong type</font>";
}else{
@copy($file, "$absolute_path/$file_name") or $endresult = "<font size="2">Couldn't Copy File To Server</font>";
}
}
}
}
echo "
<html>
Code: Select all
// config
<?
$absolute_path = "/htdocs/tms/up/files/down/"; //Absolute path to where files are uploaded
$size_limit = "yes"; //do you want a size limit yes or no.
$limit_size = "10000000"; //How big do you want size limit to be in bytes
$limit_ext = "yes"; //do you want to limit the extensions of files uploaded
$ext_count = "4"; //total number of extensions in array below
$extensions = array(".xml", ".txt", ".doc", ".xls"); //List extensions you want files uploaded to be
?>
Also have problems with this.. $php_self in the following code
Code: Select all
<body>
<a href=$PHP_SELF?action=download>Download File</a>
<a href=$websiteurl>Return to $websitename</a>
<br><br>
// and ...
<form method=POST action=$PHP_SELF?action=doupload enctype=multipart/form-data>
<p>File to upload:<br>
// tried the $_SERVER['PHP_SELF']; statement .. however that didnt
// went well
Posted: Fri Feb 06, 2004 11:47 am
by Illusionist
why dont you just remove the php_self and put the real filename in there? It always works for me...
Posted: Fri Feb 06, 2004 11:54 am
by ol4pr0
Because i am not using a download.php page
me is using a
Code: Select all
case "download":
// the code. / with form bla bla...
break;
Posted: Fri Feb 06, 2004 12:03 pm
by Illusionist
ok, back to what i said, why dont you just remove the $PHP_SELF and replace it with the filename??
instead of
Code: Select all
<a href=$PHP_SELF?action=download>Download File</a>
why not
Code: Select all
<a href=mypage.php?action=download>Download File</a>
Posted: Fri Feb 06, 2004 12:12 pm
by ol4pr0
Well i am currently working on it right about now..
also change the
Code: Select all
\ <-- normally on *nix
to --> / for the windows..
That did solve me of some erorrs.. which shouldnt really mather i think
meaning the / \ differance.
Also gave me a bunc back tho..
1 of them..
so i am back to the / .. /
Code: Select all
Parse error: parse error, unexpected '=' in download.php line 7
// line 7
absolute_path = "htdocs\tms\up\files\down"; // by changing the / 2 \
Some how it wont reconize the directories.
Code: Select all
Warning: opendir(htdocs/tms/up/files/down/): failed to open dir: Invalid argument in C:\Apache2\htdocs\tms\up\download.php on line 25
Warning: readdir(): supplied argument is not a valid Directory resource
Posted: Fri Feb 06, 2004 2:11 pm
by DuFF
Maybe you're path is wrong? Try doing this:
Code: Select all
<?php
$absolute_path = "/htdocs/tms/up/files/down/";
if(is_dir($absolute_path)) {
echo "Directory is OK";
}
else {
echo "Bad file path";
}
?>
Then you will know if the path is causing the problem or not.
Posted: Fri Feb 06, 2004 8:57 pm
by Illusionist
If your using apache on windows, then you donbt need to include the htdocs because /htdocs is the default folder