chronister Posted May 11, 2007 Share Posted May 11, 2007 I am trying to make a simple file upload page. It will not move the file properly. It only spits out the error message. Here's the code. <?php if($_POST['submit']) { if($_FILES['file_upload']['tmp_name']) { $file=$_FILES['file_upload']['tmp_name']; if(is_uploaded_file($file)) { $name=$_FILES['file_upload']['name']; $size=fsize_convert($_FILES['file_upload']['size']); $uploaddir = $_SERVER['DOCUMENT_ROOT']."/members/docs/"; $uploaddir.=$name; if(move_uploaded_file($_FILES['file_upload']['tmp_name'], $uploaddir)) { echo "Documents Updated!"; } else { echo "There was a problem when uploading the new file"; } } } } else { ?> <form action="<?=$_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="form1" id="form1"> <table width="50%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td>Title</td> <td> <input name="title" type="text" id="title" /> </td> </tr> <tr> <td>Description</td> <td> <textarea name="description" cols="35" rows="3" id="description"></textarea> </td> </tr> <tr> <td>File</td> <td><input type="file" name="file_upload" id="file_upload" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2" align="center"> <input name="submit" type="submit" id="submit" value="Submit" /> </td> </tr> </table> </form> <br /><br /><br /><br /> <?php }; if($_POST['submit']) { echo '<br><br><pre>'; print_r($_FILES); echo '</pre>'; } ?> And here is what it outputs. There was a problem when uploading the new file Array ( [file_upload] => Array ( [name] => ipconfig.txt [type] => application/x-txt [tmp_name] => /tmp/phpBehAOy [error] => 0 => 1155 ) ) Here is an echo of $uploaddir: /var/www/test/members/docs/ipconfig.txt Does anyone see a problem here?? I chmod'ed the docs directory to 0755. What am I doing wrong here?? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/50879-moving-uploaded-file/ Share on other sites More sharing options...
StormTheGates Posted May 11, 2007 Share Posted May 11, 2007 Try changing the chmod to 777. That will have full access for everyone, briefly test that. If it works you know its a chmod problem. If not you can change it back. Quote Link to comment https://forums.phpfreaks.com/topic/50879-moving-uploaded-file/#findComment-250244 Share on other sites More sharing options...
chronister Posted May 11, 2007 Author Share Posted May 11, 2007 Well, that fixed it apparently. I thought that the move_uploaded_file ran under root permissions, hence it only needed to be owner writable, and just readable for group and world. I am really new to linux and real file permissions, but I thought running a folder in 777 is a bad thing? Am I wrong here? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/50879-moving-uploaded-file/#findComment-250252 Share on other sites More sharing options...
StormTheGates Posted May 11, 2007 Share Posted May 11, 2007 Here is a little primer chart that I just made for you ----------------------------------| | Read | Write | Execute | |------|-------------|------------| |Owner| x | x | x | |------|-----|-------|------------| |Group| x | x | x | |------|-----|-------|------------| |Other | x | x | x | |---------------------------------| That is a chmod 777 What you had at 755 was ----------------------------------| | Read | Write | Execute | |------|-------------|------------| |Owner| x | x | x | |------|-----|-------|------------| |Group| x | | x | |------|-----|-------|------------| |Other | x | | x | |---------------------------------| The writing part I think was the problem. Try changing to 775(Group write) or 757(Other write) Chmod 777 isnt the best, its the most open. So try and contain it as much as possible with other peoples access. Quote Link to comment https://forums.phpfreaks.com/topic/50879-moving-uploaded-file/#findComment-250258 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.