jbashir Posted November 26, 2007 Share Posted November 26, 2007 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 Quote Link to comment Share on other sites More sharing options...
jbashir Posted November 26, 2007 Author Share Posted November 26, 2007 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 Quote Link to comment Share on other sites More sharing options...
adam291086 Posted November 26, 2007 Share Posted November 26, 2007 you say its the function not working. Where is the function setup? can i see the code? Quote Link to comment Share on other sites More sharing options...
jbashir Posted November 26, 2007 Author Share Posted November 26, 2007 I have not written this function my self. Its php function. Here it is: rename($path_to_image, $uploaded_pic) Quote Link to comment Share on other sites More sharing options...
adam291086 Posted November 26, 2007 Share Posted November 26, 2007 well if you are wanting to move the file into its final directory, which i am assuming you are from your script comment, then you need to use. move_uploaded_file ( string $filename , string $destination ) Quote Link to comment Share on other sites More sharing options...
jbashir Posted November 26, 2007 Author Share Posted November 26, 2007 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. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted November 26, 2007 Share Posted November 26, 2007 ok, what happens when the third users trys to upload a file? Quote Link to comment Share on other sites More sharing options...
jbashir Posted November 26, 2007 Author Share Posted November 26, 2007 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." Quote Link to comment Share on other sites More sharing options...
adam291086 Posted November 26, 2007 Share Posted November 26, 2007 when uploading with joe, make sure you are using a different file rename() fails with PHP4 and PHP5 under Windows if the destination file exists, regardless of file permission settings. i did some research at php.net. Quote Link to comment Share on other sites More sharing options...
jbashir Posted November 26, 2007 Author Share Posted November 26, 2007 I have tried this before, i.e., different files for both users, and there is no destination file as well before renaming. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted November 26, 2007 Share Posted November 26, 2007 well i am baffled. If the code is working for some then it should always work. There is a problem else where in the coding or joe's settings. Quote Link to comment Share on other sites More sharing options...
jbashir Posted November 26, 2007 Author Share Posted November 26, 2007 I have seen the admin section and also have seen the database. Everything for "joe" is same as "joseph". Quote Link to comment Share on other sites More sharing options...
jbashir Posted November 27, 2007 Author Share Posted November 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.