boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

upload & file permissions

 
Post new topic   Reply to topic    boardom Forum Index -> How to ?
View previous topic :: View next topic  
Author Message
jan



Joined: 07 Feb 2002
Posts: 7
Location: Vienna

PostPosted: Sun Oct 12, 2003 9:44 pm    Post subject: upload & file permissions Reply with quote

i'm using b2 0.61 for a site of a customer. using the upload feature works all fine, except that i cant access the uploaded file using a browser. i figured the file i being uploaded properly, but the file's permissions do not allow the public to download this.

i'm not sure if that's a b2 related problem, or if i should consult my webhoster about this. please help.
Back to top
View user's profile Send private message Visit poster's website
epolady



Joined: 30 Jul 2002
Posts: 800
Location: Texas

PostPosted: Sun Oct 12, 2003 9:47 pm    Post subject: Reply with quote

Make sure these 2 paths are correct in b2config.php:

$fileupload_realpath = '/home/example/public_html/images';
$fileupload_url = 'http://example.com/images';
_________________
No more support from me. Goodbye!
Go upgrade to WordPress, you'll find better support there.
Back to top
View user's profile Send private message
jan



Joined: 07 Feb 2002
Posts: 7
Location: Vienna

PostPosted: Sun Oct 12, 2003 10:04 pm    Post subject: Reply with quote

i guess if it wasnt, the file wouldnt get uploaded. as i said, it uploads to the correct directory, its just the permissions which don't allow accessing it with the browser.
Back to top
View user's profile Send private message Visit poster's website
epolady



Joined: 30 Jul 2002
Posts: 800
Location: Texas

PostPosted: Sun Oct 12, 2003 11:10 pm    Post subject: Reply with quote

What error(s) are you getting when you try to access it from the browser? Does it just now show up?
_________________
No more support from me. Goodbye!
Go upgrade to WordPress, you'll find better support there.
Back to top
View user's profile Send private message
jan



Joined: 07 Feb 2002
Posts: 7
Location: Vienna

PostPosted: Sun Oct 12, 2003 11:23 pm    Post subject: Reply with quote

a simple 403
Back to top
View user's profile Send private message Visit poster's website
epolady



Joined: 30 Jul 2002
Posts: 800
Location: Texas

PostPosted: Mon Oct 13, 2003 12:20 am    Post subject: Reply with quote

I'm assuming that you ChModded the folder to 766, also try 755, or 777.
_________________
No more support from me. Goodbye!
Go upgrade to WordPress, you'll find better support there.
Back to top
View user's profile Send private message
jan



Joined: 07 Feb 2002
Posts: 7
Location: Vienna

PostPosted: Mon Oct 13, 2003 12:45 am    Post subject: Reply with quote

unregarding how i CHMOD the folder, the file uploaded with b2 is always 600. uploading with any other software gives me 740.

tomorrow i will update my b2 and try again. this feels fishy ;)
Back to top
View user's profile Send private message Visit poster's website
epolady



Joined: 30 Jul 2002
Posts: 800
Location: Texas

PostPosted: Mon Oct 13, 2003 12:50 am    Post subject: Reply with quote

Have fun, and you're welcome.
_________________
No more support from me. Goodbye!
Go upgrade to WordPress, you'll find better support there.
Back to top
View user's profile Send private message
jan



Joined: 07 Feb 2002
Posts: 7
Location: Vienna

PostPosted: Mon Oct 13, 2003 10:43 am    Post subject: Reply with quote

sorry to come up with this again, but the problem still appears after i upgraded to the latest b2 version.

* the upload path is correct, otherwise it wouldn't allow uploading
* i tried CHMOD 766 and 777
* upload works with any other software, except b2

are there any hints left?
Back to top
View user's profile Send private message Visit poster's website
jan



Joined: 07 Feb 2002
Posts: 7
Location: Vienna

PostPosted: Fri Oct 17, 2003 11:51 pm    Post subject: Reply with quote

well, i'm mostly surprised that this issue never came up before, since it appears to be a general php problem.

anyway, here's a fixed version setting the uploaded file on 744

Code:
<?php  //Makes sure they choose a file

//print_r($HTTP_POST_FILES);
//die();

if (!empty($HTTP_POST_VARS)) { //$img1_name != "") {

   $imgalt = (isset($HTTP_POST_VARS['imgalt'])) ? $HTTP_POST_VARS['imgalt'] : $imgalt;

   $img1_name = (strlen($imgalt)) ? $HTTP_POST_VARS['imgalt'] : $HTTP_POST_FILES['img1']['name'];
   $img1_type = (strlen($imgalt)) ? $HTTP_POST_VARS['img1_type'] : $HTTP_POST_FILES['img1']['type'];
   $imgdesc = str_replace('"', '&quot;', $HTTP_POST_VARS['imgdesc']);

   $imgtype = explode(".",$img1_name);
   $imgtype = " ".$imgtype[count($imgtype)-1]." ";

   if (!ereg(strtolower($imgtype), strtolower($fileupload_allowedtypes))) {
       die("File $img1_name of type $imgtype is not allowed.");
   }

   if (strlen($imgalt)) {
      $pathtofile = $fileupload_realpath."/".$imgalt;
      $img1 = $HTTP_POST_VARS['img1'];
   } else {
      $pathtofile = $fileupload_realpath."/".$img1_name;
      $img1 = $HTTP_POST_FILES['img1']['tmp_name'];
   }

   // makes sure not to upload duplicates, rename duplicates
   $i = 1;
   $pathtofile2 = $pathtofile;
   $tmppathtofile = $pathtofile2;
   $img2_name = $img1_name;

   while (file_exists($pathtofile2)) {
       $pos = strpos($tmppathtofile, '.'.trim($imgtype));
       $pathtofile_start = substr($tmppathtofile, 0, $pos);
       $pathtofile2 = $pathtofile_start.'_'.zeroise($i++, 2).'.'.trim($imgtype);
       $img2_name = explode('/', $pathtofile2);
       $img2_name = $img2_name[count($img2_name)-1];
   }

   if (file_exists($pathtofile) && !strlen($imgalt)) {
      $i = explode(" ",$fileupload_allowedtypes);
      $i = implode(", ",array_slice($i, 1, count($i)-2));
      move_uploaded_file($img1, $pathtofile2);
      chmod($pathtofile2,0744)
      or die("Couldn't Upload Your File to $pathtofile2.");

   // duplicate-renaming function contributed by Gary Lawrence Murphy
   ?>


enjoy!
Back to top
View user's profile Send private message Visit poster's website
augapfel



Joined: 14 Feb 2004
Posts: 1
Location: Shanghai, China

PostPosted: Sat Feb 14, 2004 10:19 pm    Post subject: Reply with quote

I am also having this problem. The file upload works appropriately but the permissions on the file that I upload are set to 600. When I use an FTP program the file is uploaded with permissions set to 644. When the permissions are set to 644 I can see the image fine using a web browser. However when the permissions are set to 600 I can't see the file.

I used the code snippet supplied in the post, however this didn't seem to solve the problem.

Thanks.
Back to top
View user's profile Send private message Visit poster's website
IanH



Joined: 24 Feb 2004
Posts: 2

PostPosted: Tue Feb 24, 2004 4:15 pm    Post subject: Reply with quote

I have exactly the same problem as already listed, images are uploaded but permission is set to 600. Has anyone got a solution?
Back to top
View user's profile Send private message
IanH



Joined: 24 Feb 2004
Posts: 2

PostPosted: Wed Feb 25, 2004 4:30 pm    Post subject: Solution Found Reply with quote

Found the solution. Find the block of code:

</html><?php die();

}

if (!strlen($imgalt)) {
move_uploaded_file($img1, $pathtofile)//Path to your images directory, chmod the dir to 777
or die("Couldn't Upload Your File to $pathtofile.");
} else {
rename($img1, $pathtofile)
or die("Couldn't Upload Your File to $pathtofile.");
}

}

Change to:

</html><?php die();

}

if (!strlen($imgalt)) {
move_uploaded_file($img1, $pathtofile);//Path to your images directory, chmod the dir to 777
chmod ($pathtofile,0744)
or die("Couldn't Upload Your File to $pathtofile.");
} else {
rename($img1, $pathtofile)
or die("Couldn't Upload Your File to $pathtofile.");
}

}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> How to ? All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group