garydt Posted March 11, 2007 Share Posted March 11, 2007 i'm getting this error when i try to upload an image- Warning: unlink() [function.unlink]: Permission denied in C:\Program Files\xampp\htdocs\epeople\upim.php on line 79 Does this mean i need to change the directory permission to allow php to move/copy an image into the directory? if so, can i right-click on directory folder (i use windows xp) and go into properties and change the permissions in there? If so, what do i change it to? The code- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php if ($_SERVER['REQUEST_METHOD'] == "POST") { /* SUBMITTED INFORMATION - use what you need * temporary filename (pointer): $imgfile * original filename : $imgfile_name * size of uploaded file : $imgfile_size * mime-type of uploaded file : $imgfile_type */ /*== upload directory where the file will be stored relative to where script is run ==*/ $uploaddir = "uploads"; //-- RE-SIZING UPLOADED IMAGE /*== only resize if the image is larger than 250 x 200 ==*/ $imgsize = GetImageSize($imgfile); /*== check size 0=width, 1=height ==*/ if (($imgsize[0] > 20) || ($imgsize[1] > 20)) { /*== temp image file -- use "tempnam()" to generate the temp file name. This is done so if multiple people access the script at once they won't ruin each other's temp file ==*/ $tmpimg = tempnam("/tmp", "MKUP"); /*== RESIZE PROCESS 1. decompress jpeg image to pnm file (a raw image type) 2. scale pnm image 3. compress pnm file to jpeg image ==*/ /*== Step 1: djpeg decompresses jpeg to pnm ==*/ system("djpeg $imgfile >$tmpimg"); /*== Steps 2&3: scale image using pnmscale and then pipe into cjpeg to output jpeg file ==*/ system("pnmscale -xy 250 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile"); /*== remove temp image ==*/ unlink($tmpimg); } /*== setup final file location and name ==*/ /*== change spaces to underscores in filename ==*/ $final_filename = str_replace(" ", "_", $imgfile_name); $newfile = $uploaddir . "/$final_filename"; /*== do extra security check to prevent malicious abuse==*/ if (is_uploaded_file($imgfile)) { /*== move file to proper directory ==*/ if (!copy($imgfile,"$newfile")) { /*== if an error occurs the file could not be written, read or possibly does not exist ==*/ print "Error Uploading File."; exit(); } } unlink($imgfile); print("<img src=\"$final_filename\">"); $user = $_SESSION['MM_Username']; if ($_POST['Submit']) { if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) { //print_r($_FILES); mysql_select_db($database_elvisdb, $elvisdb); $photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"), $_FILES['imgfile']['size'])); $query = sprintf("INSERT INTO images (usnm, ImageName, imageFile) VALUES ('$user','%s', '%s')", $photo, $_FILES['imgfile']['type']); if (mysql_query($query)) { $messages[] = "Your files is successfully store in database"; } else { $messages[]= mysql_error(); } } else { $messages[] = "The file is bigger than the allowed size (96k) please reduce your file size"; } } } ?> </head> <body bgcolor="#FFFFFF"> <h2>Upload and Resize an Image</h2> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="50000"> <p>Upload Image: <input type="file" name="imgfile"><br> <font size="1">Click browse to upload a local file</font><br> <br> <input type="submit" value="Upload Image"> </form> </body> </html> <?php /*== FUNCTIONS ==*/ function getFileExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/ Share on other sites More sharing options...
supermerc Posted March 11, 2007 Share Posted March 11, 2007 Well 777 is read write and execute, you can try that. Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-204990 Share on other sites More sharing options...
garydt Posted March 11, 2007 Author Share Posted March 11, 2007 How do i do the chmod command? I did this- chmod("/epeople/upim.php", 0777); but it's not accepting it. Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-205025 Share on other sites More sharing options...
garydt Posted March 12, 2007 Author Share Posted March 12, 2007 Could someone help me with this please? Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-205367 Share on other sites More sharing options...
monk.e.boy Posted March 12, 2007 Share Posted March 12, 2007 can you do a ssh login to the site? You may have to login and run the chmod from the command line. You may be able to do it from PHP like you were in the above example, but doing: chmod 777 will set use, group and all bits, but without knowing who owns the directory and file (it may be owned by root) it's going to be hard to figure it all out. The PHP page will run as user 'apache' so if root owns the directory you won't be able to set the bits. Try 'chmod -R g+w *' and 'chmod -R u+w *' Also try chmod the directory. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-205392 Share on other sites More sharing options...
garydt Posted March 12, 2007 Author Share Posted March 12, 2007 Thanks alot. I tried what you said and now i'm getting- Warning: unlink() [function.unlink]: Permission denied in C:\Program Files\xampp\htdocs\epeople\upim.php on line 80 the last thing i've tried is <?php 'chmod 0777'; and i'm still getting- Warning: unlink() [function.unlink]: Permission denied in C:\Program Files\xampp\htdocs\epeople\upim.php on line 80 Am i getting the syntax right? How do i chmod the main directory? do i just put - chmod("\epeople\"); ? on line 80 is- unlink($imgfile); is that right? Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-205406 Share on other sites More sharing options...
monk.e.boy Posted March 12, 2007 Share Posted March 12, 2007 http://uk.php.net/chmod Have you read this? monk.e.boy Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-205416 Share on other sites More sharing options...
garydt Posted March 12, 2007 Author Share Posted March 12, 2007 That link doesn''t work but i've looked at several sites I've tried several diffrent values and i get Warning: Wrong parameter count for chmod() i put- <?php chmod(0777); if ($_SERVER['REQUEST_METHOD'] == "POST") { what am i doing wrong? Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-205644 Share on other sites More sharing options...
monk.e.boy Posted March 13, 2007 Share Posted March 13, 2007 http://uk.php.net/chmod <?php chmod("/somedir/somefile", 755); // decimal; probably incorrect chmod("/somedir/somefile", "u+rwx,go+rx"); // string; incorrect chmod("/somedir/somefile", 0755); // octal; correct value of mode ?> So you can use this to chmod any file. You don't have the file name in your function. You can also do system commands: http://uk.php.net/manual/en/function.system.php monk.e.boy Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-206079 Share on other sites More sharing options...
garydt Posted March 13, 2007 Author Share Posted March 13, 2007 Thanks for that and thanks for being patient with me. When you specify the directory/filename for the chmod command is it the actual file with the upload form or is it another file? I've put- chmod("/epeople/upim.php", 0777); and i get error- Warning: chmod() [function.chmod]: No such file or directory in C:\Program Files\xampp\htdocs\epeople\upim.php on line 10 Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-206113 Share on other sites More sharing options...
monk.e.boy Posted March 13, 2007 Share Posted March 13, 2007 Your unlink error is to do with the permissions of the file you are unlinking. So you need to fix the permissions of the file you are unlinking, then unlink it. It looks like you are trying to do a chmod on a windows machine. This probably won't work. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-206132 Share on other sites More sharing options...
garydt Posted March 13, 2007 Author Share Posted March 13, 2007 Yes, you're right, I'm using Windows XP. So where do I go from here? Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-206201 Share on other sites More sharing options...
monk.e.boy Posted March 13, 2007 Share Posted March 13, 2007 I have no idea. Let me consult google... monk.e.boy Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-206214 Share on other sites More sharing options...
monk.e.boy Posted March 13, 2007 Share Posted March 13, 2007 I have no idea. :( :o monk.e.boy Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-206236 Share on other sites More sharing options...
garydt Posted March 13, 2007 Author Share Posted March 13, 2007 ok Do you think it would work if i upload it and test it on a server? Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-206355 Share on other sites More sharing options...
monk.e.boy Posted March 14, 2007 Share Posted March 14, 2007 ok Do you think it would work if i upload it and test it on a server? Yes, no, maybe. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-206886 Share on other sites More sharing options...
garydt Posted March 14, 2007 Author Share Posted March 14, 2007 Isn't it possible to copy an upload script that works and then i can modify and i can upload it to a server to test? Or can someone with Unix test my script? Link to comment https://forums.phpfreaks.com/topic/42245-directory-permissions/#findComment-206928 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.