PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old December 9th, 2006, 03:07 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,308 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 30
Warning: unlink() [function.unlink]: Permission denied

Hi There,

How do I fix this error?

Warning: unlink() [function.unlink]: Permission denied

I am writing a form upload script for my website. I get this error when submit a blank field. My code is below. I've tried searching Google cant find anything useful. I am developing locally on my windows machine.

php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. if (isset($_POST['submitted']))
  5. {
  6.  
  7.  
  8. if (isset($_FILES['upload']))
  9. {
  10.        
  11. $allowed = array ('text/plain', 'application/msword', 'application/pdf');
  12.  
  13. if (in_array($_FILES['upload']['type'], $allowed))
  14. {
  15.        
  16. // Move File
  17.  
  18. if (move_uploaded_file($_FILES['upload']['tmp_name'], "manuals/{$_FILES['upload']['name']}"))
  19. {
  20.   echo '<h3 align="center">Success</h3>';
  21.   echo '<p class="error"><b>File Uploaded</b></p>';
  22. }
  23.   else
  24. {
  25.   echo '<p><font color="red">The file could not be uploaded because: </b>';
  26.        
  27. switch ($_FILES['upload']['error'])
  28.  
  29. {
  30. case 1:
  31. print 'The file exceeds the upload_max_filesize setting in php.ini.';
  32. break;
  33.  
  34. case 2:
  35. print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
  36. break;
  37.  
  38. case 3:
  39. print 'The file was only partially uploaded.';
  40. break;
  41.  
  42. case 4:
  43. print 'No file was uploaded.';
  44. break;
  45.  
  46. case 5:
  47.  
  48. print 'No temporary folder was available.';
  49. break;
  50.  
  51. default:
  52.  
  53. print 'A system error occurred.';
  54. break;
  55.  
  56. }
  57.                
  58. }
  59.            
  60. }
  61.  
  62. else
  63.  
  64. {
  65.   echo '<h3 class="error">Error</h3>';
  66.   echo '<p class="error">Microsoft WORD Documents and PDFs Only.</p>';
  67.   unlink ($_FILES['upload']['tmp_name']);
  68. }
  69.  
  70.  
  71.  
  72. }
  73.  
  74.  
  75.            
  76. }
  77.  
  78. ?>
  79.  
  80.  
  81.  
  82. <form enctype="multipart/form-data" action="<?=$PHP_SELF?>" method="post">
  83. <input type="hidden" name="MAX_FILE_SIZE" value="524288">
  84. <fieldset>
  85. <legend>Upload Document:</legend>
  86.  
  87. <p>
  88. <label for="upload">File:<em class="required"> (Required)</em></label>
  89. <input class="file" name="upload" id=upload type="file">
  90.  
  91.  
  92. <input class="uploadbutton" type="submit" name="submit" value="Upload">
  93. <input type="hidden" name="submitted" value="TRUE">
  94. </fieldset>
  95. </form>
  96. </body>
  97. </html>


Reply With Quote
Old December 9th, 2006, 07:46 PM
trippleweb trippleweb is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: V
Posts: 702 trippleweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 33 m 26 sec
Reputation Power: 8
RE: Warning: unlink() [function.unlink]: Permission denied

Is the file set to read only?

Reply With Quote
Old December 9th, 2006, 08:42 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,308 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 30
RE: Warning: unlink() [function.unlink]: Permission denied

I've checked that and its not.

Reply With Quote
Old December 9th, 2006, 10:29 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,308 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 30
RE: Warning: unlink() [function.unlink]: Permission denied

Here is what your code is doing - When there is no file uploaded, the ['error'] element is set to 4 and isset($_FILES['upload']) will be true. Your code then tests the ['type'] element and fails. The else statement is then executed which is the unlink(...) statement.

1) There is no need to unlink the temp file. This will be removed when the move_uploaded_file(...) executes or when the script ends.

2) You need to test the ['error'] element using your switch statement before you do any processing. Only continue processing the uploaded file if the ['error'] element is zero.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Warning: unlink() [function.unlink]: Permission denied


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap