offsprg01 Posted February 28, 2007 Share Posted February 28, 2007 so here's my problem, i've finally tracked down the soucre of my inability to access a file uploaded to my server with php's move file function. aparently the sys admin has the server set to not allow access to files that are uploaded. he says i need to write a script to chnage the permission on the fles i upload. problem is i don't have the slightest clue where to start. so can anyone point me to a good tutorial or show my how to set file permissions with php? i'm not to worried about security on this project as the end client as specified not to include security features in the web page code as they are going to be implimenting all security features once we turn the site over to them. Quote Link to comment https://forums.phpfreaks.com/topic/40480-file-upload-and-permissions-issue/ Share on other sites More sharing options...
itsmeArry Posted February 28, 2007 Share Posted February 28, 2007 while uploading the file you can set the permissions for the uploaded file as 0777 that may solve the problem chmod($fileName, 0777); Quote Link to comment https://forums.phpfreaks.com/topic/40480-file-upload-and-permissions-issue/#findComment-195860 Share on other sites More sharing options...
offsprg01 Posted February 28, 2007 Author Share Posted February 28, 2007 do i need to provide a url to the location of the file or just the file name? also where would chmod($filename, 0777); go in the following script? // Where the file is going to be placed $target_path = "../images/promo/"; $filename = basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; //now we save the file location and info in the database $startDateComp = $_POST['StartDateYear'] . '-' . $_POST['StartDateMonth'] . '-' . $_POST['StartDateDay']; $endDateComp = $_POST['EndDateYear'] . '-' . $_POST['EndDateMonth'] . '-' . $_POST['EndDateDay']; $filename = mysql_real_escape_string($filename); $startDateComp = mysql_real_escape_string(GetSQLValueString($startDateComp, "date")); $endDateComp = mysql_real_escape_string(GetSQLValueString($endDateComp, "date")); $default = GetSQLValueString($_POST['Default'], "int"); $leftRight = GetSQLValueString($_POST['LeftRight'], "int"); $id = GetSQLValueString($_POST['TITLE'], "int"); /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; if(is_uploaded_file($_FILES['uploadedfile']['tmp_name'])){ if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { chmod($filename, 0777); $uploadNotice = "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded.<br />"; $insertSQL = "UPDATE PromoImages SET FileName='$filename', StartDate='$startDateComp', EndDate='$endDateComp', `Default`='$default', LeftRight='$leftRight' WHERE ID='$id'"; } else{ $uploadNotice = "There was an error moving the file, previous file still in use!<br />"; $insertSQL = "UPDATE PromoImages SET StartDate='$startDateComp', EndDate='$endDateComp', `Default`='$default', LeftRight='$leftRight' WHERE ID='$id'"; } } else{ $uploadNotice = "You did not upload a file. Previous file will be used.<br />"; $insertSQL = "UPDATE PromoImages SET StartDate='$startDateComp', EndDate='$endDateComp', `Default`='$default', LeftRight='$leftRight' WHERE ID='$id'"; } Quote Link to comment https://forums.phpfreaks.com/topic/40480-file-upload-and-permissions-issue/#findComment-196189 Share on other sites More sharing options...
willpower Posted February 28, 2007 Share Posted February 28, 2007 its already in the script....did you put it there? if(is_uploaded_file($_FILES['uploadedfile']['tmp_name'])){ if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { chmod($filename, 0777); $uploadNotice = "The file ". basename Quote Link to comment https://forums.phpfreaks.com/topic/40480-file-upload-and-permissions-issue/#findComment-196193 Share on other sites More sharing options...
offsprg01 Posted February 28, 2007 Author Share Posted February 28, 2007 yes but it doesn't seem to be working there. i get the same permissions error Quote Link to comment https://forums.phpfreaks.com/topic/40480-file-upload-and-permissions-issue/#findComment-196204 Share on other sites More sharing options...
pixeltrace Posted February 28, 2007 Share Posted February 28, 2007 i have a related question here. how do i limit the files being uploaded let say i only want jpg, jpeg, gif, doc, or pdf to be uploaded, otherwise the file will be rejected what is the code for this? i have a working codes here but i dont know what codes to add to create a rule on the extension files $target_path = '../../uploads/'; $target_path = $target_path . basename($_FILES['resume']['name']); if(move_uploaded_file($_FILES['resume']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['resume']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } need help on this please. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/40480-file-upload-and-permissions-issue/#findComment-196211 Share on other sites More sharing options...
redarrow Posted February 28, 2007 Share Posted February 28, 2007 $_FILES['userfile']['type'] The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted. <?php $mime=array("jpeg","pdf"); foreach($mime as $x){ if($_FILES['userfile']['type']==$x){ //upload }else{ //dont } } ?> Please read the manual ok. http://uk.php.net/features.file-upload Quote Link to comment https://forums.phpfreaks.com/topic/40480-file-upload-and-permissions-issue/#findComment-196247 Share on other sites More sharing options...
offsprg01 Posted February 28, 2007 Author Share Posted February 28, 2007 well i solved my issue i just needed to add the path to the file :doh: now chmod works fine. so it's chmod (../somepath/somefile.jpg , 0777); where as i was thinking it was magic and just needed chmod(somefile.jpg , 0777); ah if only we had magic code that knew exaclty what we wnated it to do. then life you be grand. AND WE'D HAVE NO MORE MISSING SEMI COLONS! ...semi-colons are the bane of my existance. Quote Link to comment https://forums.phpfreaks.com/topic/40480-file-upload-and-permissions-issue/#findComment-196284 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.