Hello. I have a newly installed server wich is running on Debian with Apache2 and php5. the script bellow i wanted to use to upload stuff to my server but i get "Sorry, there was a problem uploading your file." all the time. i have chmoded the files and folder to 777 already., why would i get this ? index.php <form enctype="multipart/form-data" action="up.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form> HTML: up.php <?php $target = "/var/ww"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } ?> PHP:
You have forgotten to set the max file zise in the form. <input type="hidden" name="MAX_FILE_SIZE" value="5000" /> Code (markup):
Your initial $target should have a trailing forward slash: $target = "/var/ww/"; That's assuming you're not trying to preced all your uploaded file with 'ww' on purpose...
i did that on purpouse cause i dont want a max file size, or do i need to have it ? i noticed that afterwards and changed it so my target folder is "$target = "/var/www/test/";" and i still get the same error as in my first post. the folder and files is as said above chmoded 777.
The only other thing I can think of if that the owner is not the same as php (or doesn't have the same group privillages). It may be worth creating the folder via php (mkdir()) to test. The MAX_FILE_SIZE isn't a requirement.
<?php $target = "/var/www/upload"; $targetfile = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(is_writable($target)){ if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $targetfile)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } }else{ echo "Sorry, folder $target is not writable"; } ?> PHP:
Probably also need the forward slash in there... $targetfile = $target . "/" . basename( $_FILES['uploaded']['name']) ;
i got "Sorry, folder /var/www/upload/ is not writable" the owner of the folder is called "web" he owns the folder and the files so how come he is not allowed to write into it ?