nepeaNMedia Posted December 6, 2007 Share Posted December 6, 2007 Hi Folks I have seen this question posted in a couple of places but none of the answers have sorted out my problem. I have recently moved servers which also meant a new version of php, php 5.1.6. The code below, worked on the previous server but not this new one, if anyone has time could they suggest where I might be going wrong. I ftp a file to the server and then try to load the same file and it recognises that the file exists therefore, the code recognises the upload file Please help if you are able ///////the code///// <body> <? define(ULDIR,'uploads/'); chmod(ULDIR, 0777); //////////FOR RESPONSE /////////////////////// if(isset($_POST['submit'])){ /////////////////////// if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists(ULDIR . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], ULDIR . $_FILES["file"]["name"]); echo "Stored in: " . ULDIR . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } //////////FOR RESPONSE END /////////////////////// } /////////////////////// ?> <!--form--> <form action="<? $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> /////end code Quote Link to comment Share on other sites More sharing options...
nepeaNMedia Posted December 10, 2007 Author Share Posted December 10, 2007 I have since discovered that I can make this work if I set the uploads folder to 07777 using an ftp client. However, I appear unable to set those permissions on the folder dynamically in the php script Can anyone suggest how I might do this? cheers Quote Link to comment Share on other sites More sharing options...
rxbanditboy1112 Posted December 10, 2007 Share Posted December 10, 2007 the above is needed if you are using a linux or unix server. if you are using dreamweaver you can view the files on the remote server, then right click the file and set permissions. Otherwise go to your control panel for the server and figure it out from there. It'd probably be in some sort of file manager. Quote Link to comment Share on other sites More sharing options...
nepeaNMedia Posted December 10, 2007 Author Share Posted December 10, 2007 Thank you for your response But is there no way that the permissions can be set using php ie; chmod('uploads/', 0777). On a previous server I was able to do this - seeming not so now. Quote Link to comment Share on other sites More sharing options...
nepeaNMedia Posted December 10, 2007 Author Share Posted December 10, 2007 sorry, tried to post code and cannot dlete this test Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2007 Share Posted December 10, 2007 apache user has to be running as the same user as the ftp user so if you create a folder through ftp apache will be able to modify it Quote Link to comment Share on other sites More sharing options...
nepeaNMedia Posted December 10, 2007 Author Share Posted December 10, 2007 Does that mean that if I created the file through an ftp client, I cannot modify permissions using code on a php page. If this is a dumb question I appologise, it is quite late here Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2007 Share Posted December 10, 2007 it depends how the user accounts are set up on the server, sometimes you get the same user account as your ftp account, some servers apache runs as a different entity.. therefore causing the problem 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.