Jump to content

move_uploaded_file Function Problem


HBen

Recommended Posts

Hello Guys , I need Help In Upload Form

i got this Error

Warning: move_uploaded_file(): Unable to move 'C:xampptmpphpE53F.tmpto'C:/xampp/htdocs/admin/uploads/imagename.jpg'inC:xampphtdocsFinaladminadd_app.php on line23

This is The Source Code

        if (isset($_SESSION['logged_in'])) {                if (isset($_POST['doUpload'])) {                                               $title   = $_POST['title'];                        $descrip = nl2br($_POST['descrip']);                                                if (empty($title) or empty($descrip)) {                                $error = ' All fields are required ! ';                                                       } else{                                $extension = end(explode('.',$_FILES['upload']['name']));                $filename = $_FILES['upload']['name'] ;                $filetype = $_FILES['upload']['type'];                $path = $_SERVER['DOCUMENT_ROOT'] . '/admin/uploads/' . $filename;                if(move_uploaded_file($_FILES['upload']['tmp_name'],$path)) {                        $query = $db->prepare('INSERT INTO applications (APP_name,APP_descrip,Path,APP_type,APP_time) VALUES(:title,:description,:path,:type,:time)');                        $query->bindParam(':title',$_POST['title']);                        $query->bindParam(':description',nl2br($_POST['descrip']));                        $query->bindParam(':path',$filename);                                  $query->bindParam(':type',$filetype);                                  $query->bindParam(':time',time());                             $query->execute();                        header('Location: dashboard.php');                }

and this is the Html Form

<form action="add_app.php" id="newapp" method ="post" enctype="multipart/form-data"><input type="text" name="title" size="65" placeholder="Application Name"/><br /><br /><textarea rows="15" cols="65" placeholder="Application Descriptions" name="descrip"></textarea><br /><br /><div class="upload_Media btn btn-success"><span>Upload The App</span><input type="file" class="upload" name="upload"   /></div><br /><br /><input type="submit"id="doUpload" value=" Add Application"  class="ui-button btn btn-default" /></form><script type="text/javascript">$('#doUpload').on('click',function() {$('#newapp').submit();});</script>

Thank you Guys in Advance :)

Link to comment
Share on other sites

It looks like you might have an incorrect path. It seems your website is in a directory "Final" so the path should be:

$path = $_SERVER['DOCUMENT_ROOT'] . '/Final/admin/uploads/' . $filename;
Link to comment
Share on other sites

 

It looks like you might have an incorrect path. It seems your website is in a directory "Final" so the path should be:

$path = $_SERVER['DOCUMENT_ROOT'] . '/Final/admin/uploads/' . $filename;

 

I didn't get the error this time , but nothing were written on the database :(

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...