alphamoment Posted January 6, 2018 Share Posted January 6, 2018 (edited) I'm trying to upload .doc .docx and .txt files to my server but it keeps failing. I get a white screen and nothing in my uploads folder. This is my index.php <body> <form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="pic" /> <button type="submit" name="btn-upload">upload</button> </form> </body> Then this is my upload.php <?php if ($_POST['Upload'] == 'Upload') { $goodExtensions = array( '.doc', '.docx', '.txt', ); $error = ''; $uploaddir = './uploads '; $name = $_FILES['filename']['name']; $min_filesize = 10; $stem = substr($name, 0, strpos($name, '.')); $extension = substr($name, strpos($name, '.') , strlen($name) - 1); if (!in_array($extension, $goodExtensions)) $error.= 'Extension not allowed<br />'; echo "<span> </span>"; if (filesize($_FILES['filename']['tmp_name']) < $min_filesize) $error.= 'File size too small<br />' . "\n"; $uploadfile = $uploaddir . $stem . $extension; $filename = $stem . $extension; if ($error == 'wtf') { if (move_uploaded_file($_FILES['filename']['tmp_name'], $uploadfile)) { echo 'File Uploaded. Thank You.'; } } else echo $error; } ?> I'm running a DebianOS. I have the /uploads folder chmod at 777. My logs say: Warning: move_uploaded_file(./uploads uploadtest.txt): failed to open stream: Permission denied in /var/www/upload.php What am I missing? thank you in advanceAlso my files are /www/index.php /www/upload.php /www/uploads/ EDIT: Script is working fine, I just had to restart apache2 to pick up the path. If it's okay I'll leave this here if anyone needs to use this. Edited January 6, 2018 by alphamoment Quote Link to comment Share on other sites More sharing options...
Barand Posted January 6, 2018 Share Posted January 6, 2018 You do have an input named "upload" therefore $_POST['upload'] will not exist. Turn on your error reporting. Quote Link to comment Share on other sites More sharing options...
requinix Posted January 6, 2018 Share Posted January 6, 2018 - Look at the value of $uploaddir. Look at it. Carefully. Really you should have spotted this problem by reading the error message. - Your $stem and $extension assume the file doesn't have multiple periods in it. Like "bad.doc.exe". - $error will never be the value "wtf" so I don't know how you managed to get the move_uploaded_file() to (attempt to) execute in the first place. Quote Link to comment 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.