Problems with file upload under linux *solved*
Since many users have the same problem with the file upload and their is still no bug fix out,
I have had a look in the source and fixed the bug, or not realy fixed it's more
like a workaround.
Dear Devteam, please rewrite the force_mkdir function! it's a nice idea
but doesn't workout on systems where users haven't the permission to
check if the directory '/' is exists, and '/var'. The is_dir
function will always return false (because of the permissions) and the
force_mkdir function returns with false!!
Here is my workaround, I stripped the path with the Document_root Var:
(replace it in environment/functions/files.php)
-----------------------------------------------------------------------------------------------------
function force_mkdir($path, $chmod = null) {
if(is_dir($path)) return true;
$forced_path = '';
$real_path = str_replace($_SERVER["DOCUMENT_ROOT"], '', $path);
$forced_path = $path != $real_path ? $_SERVER["DOCUMENT_ROOT"] : '';
$real_path = str_replace('\\', '/', $real_path);
$parts = explode('/', $real_path);
foreach($parts as $part) {
if($forced_path == '') {
$start = substr(__FILE__, 0, 1) == '/' ? '/' : '';
$forced_path = $start . $part;
} else {
$forced_path .= '/' . $part;
} // if
if(!is_dir($forced_path) && $forced_path!='/') {
if(!is_null($chmod)) {
if(!mkdir($forced_path)) return false;
} else {
if(!mkdir($forced_path, $chmod)) return false;
} // if
} // if
} // foreach
return true;
} // force_mkdir
-----------------------------------------------------------------------------------------------------

There is a easyer way to create recrusive directorys, the mkdir
function has a third parameter (boolean) which does exactly
this.
see example for a new force_mkdir function (only example!):
<?phpfunction force_mkdir($path, $chmod = null) {
$real_path = str_replace('\\', '/', $path);
mkdir($real_path, $chmod, true);
return is_dir($real_path);
}
?>
Wow great work Martin,
Can you log this as a ticket in the tracker? I know that the number one support request we've gotten so far has been problems with initially creating directories, so if your fix relates to that then PP almost definitely wants it.
What systems have you tested this on? Can you think of any places where it might not work, or a reason why Illiija would have written it this way instead?
Thanks mate!
I haven't tested it yet, (only on my linux server). so it needs to be tested on several systems..
Ticket in tracker is created!
Linux server...
With the new force_mkdir function from Martin I get the message that it can't create all the folders, but in fact the are created. So for me there is another problem. The uploaded Files don't get stored into the new folders.
So what can I do?
thanks,
Hermann
Hi Martin,
Did you get the error where it said 'Failed to create folder at...' error?
If so, I am wondering whether this would fix it for me as it is the only problem I am having.
And I am not really familiar with php, could you tell me what I need to replace the force_mkdir function with please?
Thanks,
Ambrose
I think there is a bigger differents between linux and windows systems!
Can you write which php version you've used?
Can you send the exact error message? or a screenshot?
if the directory was createt than the is_dir function shoud return
true, and it shoud work...
which php version and which system do you use?
Hi Martin I simply get
"Failed to create folder '/var/www/web34/html/upload/fff3a/793aa/f0747'"
I tried the debug mode, but that doesn’t give me more Information.
I just checked again, the Directories are there but nothing in them.
Is it OK if I delete them? Would that break the Data Base?
Thanks,
Hermann
The exact error is:
Failed to create folder 'C:\Inetpub\vhosts\choyster.me.uk\httpdocs\project/upload/a57ff/aa5c1/dfd45'
I can create folders but I can't add a file to it, I get this error each time I try.
According to the Plesk on my domain, I am running php v5.2.0 and I think MySql 5.0.27.
Thanks,
Ambrose
Thanks to Martin's speedy response, I can confirm that the fix works for uploading files on Windows IIS!
Many thanks Martin,
Ambrose
Hi Ambrose,
all though we use different Servers (I use a LAMP Installation), can you post what your solution was?
thanks,
Hermann
Hi Hermann,
Sorry for the late reply, I got the file directly from Martin, not sure what's actually changed apart from the fact that it works!
Let me know if you'd like a copy of the file, I can forward Martin's copy to you.
Cheers,
Ambrose
Yes can you send me the pach. I guess it will be includet in the next release, but for now I culd test it on my systm. Can you send the file to
ht ( at ) avance-marketing.de
Thanks,
Hermann
Worked for me. Linux system. Fedora Core 4, PHP 5+, Apache 2
for some reason did not work for me under iis 6.0 and latest PP. I get the same error:
Failed to create folder 'D:\inetpub\vhosts\site.mysite.com\httpdocs/upload/b282b/e0b2b/e33fe'
uploading avatars and logos works fine.
any idea?
EDIT: finally got it working fine with files by Martin. Thanks Martin and Ambrose.
Failed to create folder '/home/imsoper/public_html/projects/upload/b59d5/dd411/9fddc'
I'm getting the same error. My web host is running linux.
I can also upload logos & avatars with no problems.
Ian
Hi there,
there is another problem with uploading files.
ProjectPier does not using
<?phpmove_uploaded_file();
?>
PHP function for uploading and files handling and this is no good.
Why? On **shared** web hosting or with **safe_mod on** is problem with restriction and permissions.
**For example**
I am using shared web hosting (I can not edit php.ini and other settings). My upload dir is shared **/home/www/tmp/** and I have not access to this folder directly. ProjectPier have to upload file to this folder (standard procedure) and then do
<?phpmove_uploaded_file();
?>
to another folder, where can read/write.
In file applications/controllers/FilseController.class.php on line (about) 390 is
<?php$uploaded_file = array_var($_FILES, 'file_file');
?>
and some other
<?phpsetFilename();
?>
functions and uploading files does not work.
**When I modify** this code like this
<?php$uploaded_file = array_var($_FILES, 'file_file'); // move uploaded file to folder where I can read and write
move_uploaded_file($uploaded_file["tmp_name"], "./tmp/".$uploaded_file["tmp_name"]);
$uploaded_file["tmp_name"] = "./tmp".$uploaded_file["tmp_name"];
?>
file upload is working cool. This my solution is ugly, I am sure, there is easier and clearer way.
The same problem is for example on page with avatar uploading. This does not work. Why? Uploaded file is in public folder (hosting shared tmp folder) and ProjectPier trying this:
<?php// ...
!is_readable($avatar['tmp_name']
// ...
?>
this return error because of $avatar[‘tmp_name’] is not readable. This is on line about 309 in application/controllers/AccountController.class.php
**When I modify code like this:**
<?php$avatar = array_var($_FILES, 'new_avatar');
move_uploaded_file($avatar["tmp_name"], "./tmp/".$avatar["tmp_name"]);
$avatar["tmp_name"] = "./tmp".$avatar["tmp_name"];
?>
I can upload avatar.
Is it solution? I am sure, it is.
In safe_mode (and not only) we have to use move_uploaded_file() instead of copy(). move_uploaded_file() copy uploaded file to my folder where I can do anything.
In PHP 6 this will be one way to upload :)
**From PHP.NET**
Note: move_uploaded_file() is both safe mode and open_basedir aware. However, restrictions are placed only on the destination path as to allow the moving of uploaded files in which filename may conflict with such restrictions. move_uploaded_file() ensures the safety of this operation by allowing only those files uploaded through PHP to be moved.
I hope, it helps.
Sorry for my English, I am from Czech Republic.
I'm on version 08.0.2 and I'm having the same problem.
Failed to create folder '/home/blahblah/public_html/project/upload/7a48a/b5a36/92e80'
Permissions looks good and everything ...