Jump to content

Problem in rename function


jbashir

Recommended Posts

I am facing uploading problem in php script. I have two users:

 

1. joseph

2. joe

 

Both users have the same privileges and can upload the images. The problem I am facing is, that user "joseph" can upload the images while "joe" can not. I have gone through the script line by line and have echo(d) the results line by line for both users and have seen that the problem occurs at the

rename($path_to_image, $uploaded_pic) 

function. For "joseph" the file/dir is renamed but for "joe" it does not. Again I say that both the users are registered users and have the same privileges. Can someone please help me? Here is the code:

 

// Create path for final location.
$uploaded_pic = $dest_dir . $picture_name;

// Form path to temporary image.
$path_to_image = './'.$CONFIG['fullpath'].'edit/'.$file_set[1];
// prevent moving the edit directory...
if (is_dir($path_to_image))
cpg_die(CRITICAL_ERROR, $lang_upload_php['failure'] . " - '$path_to_image'", __FILE__, __LINE__, true);

echo "path to imnage: ".$path_to_image;
echo "uploaded pic: ".$uploaded_pic;
echo "entreing rename function";

/* same results are echo(ed) for both user till here. But below this only "joseph" can enter successfully, not "joe"*/

//Move the picture into its final location
if (rename($path_to_image, $uploaded_pic)) {
echo "in rename";
exit; 

Thanks

 

Joseph Bashir

Ufnasoft

http://ufnasoft.com

Link to comment
Share on other sites

I posted this problem today morning but still there is no reply from someone. Here is some more about the problem.

 

I am using Coppermine Photo Gallery (a php module) http://coppermine-gallery.net/  for uploading and managing images. The problem is occuring in upload.php file. If someone has used this module and can take some time to look into the problem.  Your help will be much appreciated.

 

Thanks

Link to comment
Share on other sites

Thanks, you are right. But my problem is that I am using a ready-made module and do not want to change the code. Plus, the code is working fine for the other two users but hinders the third user to upload the files while all users have the same privileges. And the problem, as I mentioned in my first post, occurs at the rename() function.

Link to comment
Share on other sites

I also posted this code in my first post.

 

// Create path for final location.
$uploaded_pic = $dest_dir . $picture_name;

// Form path to temporary image.
$path_to_image = './'.$CONFIG['fullpath'].'edit/'.$file_set[1];
// prevent moving the edit directory...
if (is_dir($path_to_image))
cpg_die(CRITICAL_ERROR, $lang_upload_php['failure'] . " - '$path_to_image'", __FILE__, __LINE__, true);

echo "path to imnage: ".$path_to_image;
echo "uploaded pic: ".$uploaded_pic;
echo "entreing rename function";

/* same results are echo(ed) for both user till here. But below this only "joseph" can enter successfully, not "joe"*/

//Move the picture into its final location
if (rename($path_to_image, $uploaded_pic)) {
echo "in rename";
exit; 

 

Everything goes same for both users just before rename() function. Then for user "joseph" the file/dir is renamed but for user "joe" it is not. Rather it goes to the else part of the if statement and displays the error "File could not be placed successfully."

 

Link to comment
Share on other sites

Hi adam291086

 

Again I have gone through the problem and have found that:

 

PHP script creates user folder with 0777 privileges. Here is the code:

$filepath = $CONFIG['userpics'] . (USER_ID + FIRST_USER_CAT);
$dest_dir = $CONFIG['fullpath'] . $filepath;
if (!is_dir($dest_dir)) {
// the dir is created with 0777 privileges
mkdir($dest_dir, octdec($CONFIG['default_dir_mode']));
if (!is_dir($dest_dir)) 
cpg_die(CRITICAL_ERROR, sprintf($lang_db_input_php['err_mkdir'], $dest_dir), __FILE__, __LINE__, true);

 

Even though the dir has 0777 permissions still the rename($path_to_image, $uploaded_pic) function cannot move the file to destination dir. In this case not even the move_uploaded_file ( string $filename , string $destination ) function works.

 

On the other hand, when I create the folder manually via FTP Client with 0777 permissions everything goes well.

 

In both cases (folder created by php script, and folder created manually through FTP Client), the folder has 0777 permissions, but in the first case it does not work while in the second it works. Can you please help to figureout what could be the problem here? Thanks

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.