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 Link to comment https://forums.phpfreaks.com/topic/80401-uploading-files/ 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 Link to comment https://forums.phpfreaks.com/topic/80401-uploading-files/#findComment-410735 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. Link to comment https://forums.phpfreaks.com/topic/80401-uploading-files/#findComment-410741 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. Link to comment https://forums.phpfreaks.com/topic/80401-uploading-files/#findComment-410848 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 Link to comment https://forums.phpfreaks.com/topic/80401-uploading-files/#findComment-410851 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 Link to comment https://forums.phpfreaks.com/topic/80401-uploading-files/#findComment-410852 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 Link to comment https://forums.phpfreaks.com/topic/80401-uploading-files/#findComment-410935 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 Link to comment https://forums.phpfreaks.com/topic/80401-uploading-files/#findComment-410938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.