Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 3
upload an image? 
 
Melinda
Member
 
Total Posts:  49
Joined:  2007-08-31
 

Each time I try to upload an image for a product I get:
Unable to create directory ‘/’. Access forbidden.

The media/upload folder along with all the media folders are 777.

What else needs to be done to upload an image and attach it to a product?

 
Magento Community Magento Community
Magento Community
Magento Community
 
brians
Jr. Member
 
Avatar
Total Posts:  14
Joined:  2007-09-05
 

just a guess—do you got a OPEN_BASEDIR RESTRICTION IN EFFECT error?
I get the same problem, and I get that error. I’ve asked my hosting co about disabling this, have yet to hear back.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Melinda
Member
 
Total Posts:  49
Joined:  2007-08-31
 

This is all I could find in my logs:

[Mon Sep 10 20:46:41 2007] [error] [client 75.41.160.141] Directory index forbidden by Options directive: /var/www/vhosts/designhosting.us/httpdocs/magento/testMelinda/magento/media/upload/0/, referer: http://www.designhosting.us/magento/testMelinda/magento/admin/catalog_product/edit/id/108/
[Mon Sep 10 20:46:41 2007] [error] [client 75.41.160.141] Directory index forbidden by Options directive: /var/www/vhosts/designhosting.us/httpdocs/magento/testMelinda/magento/media/upload/1/, referer: http://www.designhosting.us/magento/testMelinda/magento/admin/catalog_product/edit/id/108/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Melinda
Member
 
Total Posts:  49
Joined:  2007-08-31
 

can anyone help please?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan Orsborne
Member
 
Total Posts:  72
Joined:  2007-09-20
 

The file upload doesn’t work on Windows. I’m looking into fixing it in my verision but in the meantime you can simply disable it as a required field but going to the eav_attribute table and setting is_required = 0

 
Magento Community Magento Community
Magento Community
Magento Community
 
Melinda
Member
 
Total Posts:  49
Joined:  2007-08-31
 

Thanks I will do that.

I have a linux server that it doesn’t work on.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan Orsborne
Member
 
Total Posts:  72
Joined:  2007-09-20
 

I think I’ve fixed it..... can someone test and confirm and perhaps it could be included in a quick new release to help everyone else out.

I’ve edited \lib\Varien\File\Uploader.php and changed the function _createDestinationFolder.
The problem was caused by this line:

$newPath.= ( $newPath != DIRECTORY_SEPARATOR ) ? DIRECTORY_SEPARATOR . $directory : $directory;

Which would build the path with a \user\ etc etc structure for Linux. I’ve added a new variable (which could/should go into the core settings but I’ve not done that yet) to say which system you are running the code on and then switched to a different line if it is a Win32 system:

$newPath.= $directory . DIRECTORY_SEPARATOR;

This builds c:\ etc etc.

The complete code to replace is:

private function _createDestinationFolder($destinationFolder)
{
if( !$destinationFolder ) {
return;
}

//Start Edit
$this->_system = “Win32”;
//End Edit

$path = explode(DIRECTORY_SEPARATOR, $destinationFolder);
$newPath = null;
$oldPath = null;
foreach( $path as $key => $directory ) {

//Start Edit
if ($this->_system != “Win32"){
$newPath.= ( $newPath != DIRECTORY_SEPARATOR ) ? DIRECTORY_SEPARATOR . $directory : $directory;
} else {
$newPath.= $directory . DIRECTORY_SEPARATOR;
}
//End Edit

if( is_dir($newPath) ) {
$oldPath = $newPath;
continue;
} else {


if( is_writable($oldPath) ) {
mkdir($newPath, 0777);
} else {
throw new Exception("Unable to create directory ‘{$newPath}’. Access forbidden.");
}
}
$oldPath = $newPath;
}
return $this;
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan Orsborne
Member
 
Total Posts:  72
Joined:  2007-09-20
 

Just another thought....

If this solution doesn’t help then you can debug the file path by changing the following lines:

if( is_writable($oldPath) ) {
mkdir($newPath, 0777);
} else {
throw new Exception("Unable to create directory ‘{$newPath}’. Access forbidden.");
}

to

if( is_writable($oldPath) ) {
mkdir($newPath, 0777);
} else {
//throw new Exception("Unable to create directory ‘{$newPath}’. Access forbidden.");
echo $oldPath;
echo $newPath
}

That should help you track down any other problems

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Melinda
Member
 
Total Posts:  49
Joined:  2007-08-31
 

I’m not sure about your quote marks around Win32 but I just tried it and still get the same error.

This is the code I used:

private function _createDestinationFolder($destinationFolder)
    
{
        
if( !$destinationFolder {
            
return;
        
}
        
//Start Edit
$this->_system "Win32";
//End Edit 

        
$path explode(DIRECTORY_SEPARATOR$destinationFolder);
        
$newPath null;
        
$oldPath null;
        foreach( 
$path as $key => $directory {

//Start Edit
if ($this->_system != "Win32"){
$newPath
.= ( $newPath != DIRECTORY_SEPARATOR ) ? DIRECTORY_SEPARATOR $directory $directory;
else {
$newPath
.= $directory DIRECTORY_SEPARATOR;
}
//End Edit 

            
if( is_dir($newPath) ) {
                $oldPath 
$newPath;
                continue;
            
else {
                
if( is_writable($oldPath) ) {
                    mkdir
($newPath0777);
                
else {
                    
throw new Exception("Unable to create directory '{$newPath}'. Access forbidden.");
                
}
            }
            $oldPath 
$newPath;
        
}
        
return $this;
    
}

The error is:
Unable to create directory ‘/’. Access forbidden.

I looked in my logs and now get no errors listed so I don’t know about this.

I’m on a linux server with centos 5, php 5.1.6-12 and mysql 5.0 using plesk 8.2 as an admin.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Melinda
Member
 
Total Posts:  49
Joined:  2007-08-31
 

I tried the debug code you listed and it gives me a totally blank page after trying to upload an image and no view source either.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan Orsborne
Member
 
Total Posts:  72
Joined:  2007-09-20
 

This is a Win32 solution to the error “Unable to create directory ‘\C:’. Access forbidden”

If you want to debug the Linux code you will need to echo the lines I mentioned in my susequent post. This will show you where it is trying to create the directory so you can track down the problem.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

For Windows users, upload attached file as:

lib/Varien/File/Uploader.php
File Attachments
Uploader.php  (File Size: 11KB - Downloads: 582)
 
Magento Community Magento Community
Magento Community
Magento Community
 
Melinda
Member
 
Total Posts:  49
Joined:  2007-08-31
 

If you want to debug the Linux code you will need to echo the lines I mentioned in my susequent post. This will show you where it is trying to create the directory so you can track down the problem.

I already tried the debug and I only get a totally blank page that shows nothing.  Maybe I’m not understanding what to do.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Melinda
Member
 
Total Posts:  49
Joined:  2007-08-31
 

Do the images have to be in a certain folder on your harddrive before the upload will work or can you get images from any folders on your harddrive?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@Melinda: Location of images on your harddrive doesn’t matter as long as they have readable permission.

Did you try updating Uploader.php file attached above?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Melinda
Member
 
Total Posts:  49
Joined:  2007-08-31
 

Yes I tried your change but I’m still getting this same error message which is driving me nuts.  Now, I’m not getting any error messages in the logs so I cannot figure it out.  I may try a new install for php 5.1.6 but has the cgi-bin been put in there from the wiki page because the last download did not have a cgi-bin to follow those instructions?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 3