I was working on a script for uploading files. I kept running into troubles after i migrated everything from my local testserver to the webserver of my isp. Finally i decided to start a little test-project to get to the problem.
After a while i found out that the directory i create doest get the correct chmod-mode.
I can check this when i log into my domain with the admin page-thingy. i see that the directory created has neither READ nor WRITE enabled
here is what happens:
1. I run the script for the first time
2. the directory 'upload_files' is created and mode is set (in code at least)
3. afterwards no file is uploaded
4. when i check the mode from my ISP-admin-page READ nor WRITE is checked.
5. so no file is uploaded
my thoughts:
file modes can be set for Owner, Group and Global; but the admin page only shows two checkboxes; READ and WRITE. i don't know which read/write this is, so i tried a couple of chmod-variants. but no luck.
can anyone please help?!
im not sure what kind of server (unix or windows) my pages are running, does that have anything to do with it?
here's the code
Code: Select all
<?php
error_reporting(E_ALL);
echo $site_name = $_SERVER['HTTP_HOST'];
echo $url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
echo $url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
echo $upload_dir = "upload_files/";
echo $upload_url = $url_dir."/upload_files/";
echo $message ="";
// DEBUGGING
//var_dump($_FILES);
//$a=stat($upload_dir);
//var_dump($a);
//echo "<br>";
//echo $a[mode];
//create upload_files directory if not exist
//If it does not work, create on your own and change permission.
if (!is_dir("upload_files")) {
mkdir("upload_files",0777);
die ("upload_files directory doesn't exist, now it's created'");
}
if ($_FILES['userfile']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
$message = "Invalid File Specified.";
}
print $message;
function do_upload($upload_dir, $upload_url) {
$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result = $_FILES['userfile']['error'];
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;
//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
//File Size Check
else if ( $file_size > 500000) {
$message = "The file size is over 500K.";
return $message;
}
//File Type Check
else if ( $file_type == "text/plain" ) {
$message = "Sorry, You cannot upload any script file" ;
return $message;
}
$result = move_uploaded_file($temp_name, $file_path);
$message = ($result)?"File url <a href=$file_url>$file_url</a>" :
"Somthing is wrong with uploading a file.";
return $message;
}
?>
<form name="upload" id="upload" action="<?php echo $PHP_SELF ?>" ENCTYPE="multipart/form-data" method="post">
Upload Image<input type="file" id="userfile" name="userfile">
<input type="submit" name="upload" value="Upload">
</form>feyd | please use
Code: Select all
tags when posting large blocks of php code.[/color]