PHPiSean Posted February 18, 2011 Share Posted February 18, 2011 I've looked over it a couple times and I still get the error. Here's the code <?php require('header.php'); require('links.php'); $name = mysql_real_escape_string($_POST['file']); $url = mysql_real_escape_string($_POST['file']); $filename = $_FILES['file']['name']; $temp = $_FILES['file']['tmp_name']; $error = $_FILES['file']['error']; $sql = "insert into books set name='$name', url='$url'"; if(isset($_POST['submit'])) { if($error > 0) { die("Error uploading file! Code $error."); }else{ move_uploaded_file($temp,"/center/resources/books/".$filename); mysql_query($sql); } } ?> <form method='post' enctype='multipart/form-data'> Book Name<input type="text" name="name"></br> File<input type="file" name="file"></br> <input type="submit" name="submit" value="Upload"> </form> Link to comment https://forums.phpfreaks.com/topic/228077-file-upload-form-not-working-correctly/ Share on other sites More sharing options...
gizmola Posted February 18, 2011 Share Posted February 18, 2011 It helps if you actually state what error you're getting. With that said, this is obviously wrong: $sql = "insert into books set name='$name', url='$url'"; An insert statement format that might actually work: $sql = "insert into books (name, url) values ('$name', '$url')"; Link to comment https://forums.phpfreaks.com/topic/228077-file-upload-form-not-working-correctly/#findComment-1176102 Share on other sites More sharing options...
PHPiSean Posted February 18, 2011 Author Share Posted February 18, 2011 The sql works, that doesn't happen to be the issue. The issue is that I cannot upload the file. I get the error Error uploading file! Code $error. Link to comment https://forums.phpfreaks.com/topic/228077-file-upload-form-not-working-correctly/#findComment-1176103 Share on other sites More sharing options...
PHPiSean Posted February 18, 2011 Author Share Posted February 18, 2011 The sql works, that doesn't happen to be the issue. The issue is that I cannot upload the file. I get the error Error uploading file! Code $error. Since that's the error I set Link to comment https://forums.phpfreaks.com/topic/228077-file-upload-form-not-working-correctly/#findComment-1176107 Share on other sites More sharing options...
PHPiSean Posted February 18, 2011 Author Share Posted February 18, 2011 I have also found errors given by the browser Warning: move_uploaded_file(/center/resources/books/sources.pdf) [function.move-uploaded-file]: failed to open stream: No such file or directory Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move Link to comment https://forums.phpfreaks.com/topic/228077-file-upload-form-not-working-correctly/#findComment-1176114 Share on other sites More sharing options...
codingPhoenix Posted February 18, 2011 Share Posted February 18, 2011 Hiya PHPiSean, okies i know it sounds stupid but are your permissions set for /books/ ? also is that the proper path to your dir? Cheers!! Link to comment https://forums.phpfreaks.com/topic/228077-file-upload-form-not-working-correctly/#findComment-1176115 Share on other sites More sharing options...
gizmola Posted February 18, 2011 Share Posted February 18, 2011 Well, the longer I work with Mysql the less it surprises me when they cook up some crazy non-standard syntax. The error you're having is definately a path or permissions issue. Does the path: /center/resources/books/ actually exist? This can't be a relative path, it has to be a real path on the server. It will not make directories for you either -- they have to exist or the move_uploaded_file fails. And as already suggested by codingPhoenix, the directory has to have rwx perms that apply to the apache process as well. Link to comment https://forums.phpfreaks.com/topic/228077-file-upload-form-not-working-correctly/#findComment-1176142 Share on other sites More sharing options...
PHPiSean Posted February 18, 2011 Author Share Posted February 18, 2011 I set the permissions for books to 777. /center/resources/books directory does exist. center comes right after the website root Link to comment https://forums.phpfreaks.com/topic/228077-file-upload-form-not-working-correctly/#findComment-1176430 Share on other sites More sharing options...
PHPiSean Posted February 18, 2011 Author Share Posted February 18, 2011 I even tried to do it from the root of the server from /var/ still didn't work Link to comment https://forums.phpfreaks.com/topic/228077-file-upload-form-not-working-correctly/#findComment-1176437 Share on other sites More sharing options...
gizmola Posted February 19, 2011 Share Posted February 19, 2011 Does your server configured with open basedir or safe mode? Link to comment https://forums.phpfreaks.com/topic/228077-file-upload-form-not-working-correctly/#findComment-1176618 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.