File Uploading error
Moderator: General Moderators
File Uploading error
I have this error when I upload files
Warning: open_basedir restriction in effect. File is in wrong directory in /home/webcindario/php-test/uploadprueba.php on line 27
here is the code
<HTML>
<TITLE>
File upload
</title>
<body>
<B>File upload</b>
<form enctype="multipart/form-data" action="<?PHP echo $PHP_SELF ?>" method="post">
<!-- "MAX_FILE_SIZE" determines the biggest size an uploaded file can occupy -->
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
Send this file:
<input name="userfile" type="file">
<input type="submit" name="submit" value="Send File">
</form>
</body>
<?php
/*
$userfile - The temporary filename in which the uploaded file was stored on the server machine.
$userfile_name - The original name or path of the file on the sender's system.
$userfile_size - The size of the uploaded file in bytes.
$userfile_type - The mime type of the file if the browser provided this information. An example would be "image/gif".
*/
// copy to this directory
$dir="./home/webcindario/php-test/";
if ($submit){
copy($userfile,$dir.$userfile_name);
if (!is_uploaded_file ($userfile)){
echo "<b>$userfile_name</b> couldn't be copied !!";
}
}
// check whether it has been uploaded
if (is_uploaded_file ($userfile)){
echo "
<b>$userfile_name</b> copied succesfully !!";
}
?>
</html>
I´m using a free web hosting if it help.
Warning: open_basedir restriction in effect. File is in wrong directory in /home/webcindario/php-test/uploadprueba.php on line 27
here is the code
<HTML>
<TITLE>
File upload
</title>
<body>
<B>File upload</b>
<form enctype="multipart/form-data" action="<?PHP echo $PHP_SELF ?>" method="post">
<!-- "MAX_FILE_SIZE" determines the biggest size an uploaded file can occupy -->
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
Send this file:
<input name="userfile" type="file">
<input type="submit" name="submit" value="Send File">
</form>
</body>
<?php
/*
$userfile - The temporary filename in which the uploaded file was stored on the server machine.
$userfile_name - The original name or path of the file on the sender's system.
$userfile_size - The size of the uploaded file in bytes.
$userfile_type - The mime type of the file if the browser provided this information. An example would be "image/gif".
*/
// copy to this directory
$dir="./home/webcindario/php-test/";
if ($submit){
copy($userfile,$dir.$userfile_name);
if (!is_uploaded_file ($userfile)){
echo "<b>$userfile_name</b> couldn't be copied !!";
}
}
// check whether it has been uploaded
if (is_uploaded_file ($userfile)){
echo "
<b>$userfile_name</b> copied succesfully !!";
}
?>
</html>
I´m using a free web hosting if it help.
for starters you have a dot in the destination dir which I don't think you want:
The second thing to check is that permissions are correct, ie you may find you need to create subdir and chmod a+rw it
Also,
is dagerous, as it looks like your uploading into same dir as the scripts without renaming the file, so what will happen if someone uploads a file called index.php?
The finall thing to be aware of is, the is_uploaded_file function should be used for sanity checking and to to check if the file has been successfully dealt with. So rather than:
you want:
Code: Select all
// copy to this directory
$dir="./home/webcindario/php-test/";Also,
Code: Select all
copy($userfile,$dir.$userfile_name);The finall thing to be aware of is, the is_uploaded_file function should be used for sanity checking and to to check if the file has been successfully dealt with. So rather than:
Code: Select all
if ($submit){
copy($userfile,$dir.$userfile_name);
if (!is_uploaded_file ($userfile)){
echo "<b>$userfile_name</b> couldn't be copied !!";
}Code: Select all
if (is_uploaded_file){
copy($userfile,$dir.$userfile_name);
if (!is_uploaded_file ($userfile)){
echo "<b>$userfile_name</b> couldn't be copied !!";
} else {
echo "No Upload happened";
}phpinfo() to see what you have for open_basedir
Php manual:
"The restriction specified with open_basedir is actually a prefix, not a directory name. This means that "open_basedir = /dir/incl" also allows access to "/dir/include" and "/dir/incls" if they exist. When you want to restrict access to only the specified directory, end with a slash. For example: "open_basedir = /dir/incl/"
Php manual:
"The restriction specified with open_basedir is actually a prefix, not a directory name. This means that "open_basedir = /dir/incl" also allows access to "/dir/include" and "/dir/incls" if they exist. When you want to restrict access to only the specified directory, end with a slash. For example: "open_basedir = /dir/incl/"
well this is what phpinfo say.McGruff wrote:phpinfo() to see what you have for open_basedir
Php manual:
"The restriction specified with open_basedir is actually a prefix, not a directory name. This means that "open_basedir = /dir/incl" also allows access to "/dir/include" and "/dir/incls" if they exist. When you want to restrict access to only the specified directory, end with a slash. For example: "open_basedir = /dir/incl/"
open_basedir /home/webcindario/php-test
How I change the permision on this path, (is the root), because the FTP program only let me change the permisions of the files and subdirectories.
Well I solve half problem, this is what I made.
1 - Switch the copy function by move_uploaded_file, because this work with safe mode. Doing this the file was transfer.
2- the only problem is that a warning message is showed.
Warning: SAFE MODE Restriction in effect. The script whose uid is 48 is not allowed to access /tmp owned by uid 0 in /home/webcindario/php-test/myupload.php on line 7
Is there some way to remove this warning?
1 - Switch the copy function by move_uploaded_file, because this work with safe mode. Doing this the file was transfer.
2- the only problem is that a warning message is showed.
Warning: SAFE MODE Restriction in effect. The script whose uid is 48 is not allowed to access /tmp owned by uid 0 in /home/webcindario/php-test/myupload.php on line 7
Is there some way to remove this warning?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You can't get around safe-mode restrictions without some help from your host. Have a read of:
http://www.php.net/manual/en/features.safe-mode.php
Mac
http://www.php.net/manual/en/features.safe-mode.php
Mac