0

I'm trying to upload some images to server. But when i submit the form it will not write the file in the directory. I don't know how to get the exception in php(I'm new to php).

code :

$target = "assets/images/";
$target = $target . basename( $_FILES['file1']['name']);
//Writes the file to the server
if(move_uploaded_file($_FILES['file1']['tmp_name'], $target))
{
  $uploadRes=true;
  echo "sucess";
}
else {
  $uploadRes=false;
  echo "failed";
}

Edit:

Html :

 <form class="form-horizontal" id="addpost" method="GET" action="" name="newpost">
        <div class="control-group">
            <label class="control-label" for="form-field">Post Title</label>
            <div class="controls">
                <input type="text" id="form-field" placeholder="Post Title" name="Post_title" value="" />
             </div>
         </div>
         <div class="control-group">
         <label class="control-label" for="form-field-11">Content Here</label>
            <div class="controls">
            <textarea name="post_content"  value="" class="autosize-transition span12" id="form-field-11" style="overflow: hidden; word-wrap: break-word; resize: horizontal; height: 67px;"></textarea>
            </div>
           </div><!-- Insert Image Code -->
           <div class="control-group">
            <div class="widget-main">
                <div class="controls">
                    <div class="ace-file-input">
                        <input id="id-input-file-2" type="file" name="file1">
                        <a class="remove" href="#"></a>
                    </div>
                 </div>
                 <div class="controls">
                    <div class="ace-file-input ace-file-multiple">
                    <input id="id-input-file-3" type="file" multiple="" name="file2">
                        <a class="remove" href="#">
                        <i class="icon-remove"></i>
                        </a>
                    </div>
                    <label>
                    <input id="id-file-format" type="checkbox" name="file-format">
                        <span class="lbl"> Allow only images</span>
                    </label>
                </div>
              </div>
             </div><!-- Insert Image Code -->
            <div class="space-4"></div>
            <div class="control-group">
        <label class="control-label" for="form-field-tags">Tag input</label>
                <div class="controls">
                    <input id="form-field-tags" type="hidden" placeholder="Enter tags ..." value="Tag Input Control" name="tags">
                </div>
            </div>

            <div class="space-4"></div>
            <div class="control-group">
                <label class="control-label" for="form-field-select-3">Select Category</label>
                <div class="controls">
                <label for="form-field-select-3">Chosen</label>
                <select class="chzn-select" id="form-field-select-3" data-placeholder="Choose a Category..." name="category">
                <option value="">
                </option><option value="Blog">Blog
                </option><option value="News Letter">News Letter
                </option></select>
             </div>
           </div>

     <div class="control-group" style="float:left; margin-right:25px">
        <div class="controls"><button type="submit" class="btn btn-info">
        <i class="icon-ok bigger-110"></i>
        <input type="submit" value="" id="posubmit" style="opacity:0"/>Submit</button>
        <button type="reset" class="btn"><i class="icon-undo bigger-110"></i>Reset</button>
        </div>
     </div> 
     <div id="resp" style="float:left; margin-top:5px">
        <img id="loading" style="visibility:hidden;" src="assets/img/ajax-load.gif" width="16" height="16" alt="loading" />
      </div>
     </form>

I'm submitting the form with ajax.. Any help would be appreciated.

9
  • 1
    Can you show the html.? Commented Oct 16, 2013 at 10:48
  • 1
    Does the directory have write permission?? Commented Oct 16, 2013 at 10:48
  • have u tried to debug it?? Commented Oct 16, 2013 at 10:50
  • So you upload something to your directory through php? You can also upload it in the server. I asked a question like this: stackoverflow.com/questions/19359101/… I used this: bytes.com/topic/php/insights/… Just a comment. This shouldn't solve your problem but still just wanted to let you know. Maybe it is a solution cause you can choose a directory to save it in. Commented Oct 16, 2013 at 10:51
  • 2
    You have a random 0 knocking about also, after $uploadRes=false;. Commented Oct 16, 2013 at 10:52

1 Answer 1

1

your form tag in html should be like the following :

<form class="form-horizontal" id="addpost" method="GET" action="" name="newpost" enctype="multipart/form-data" >
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.