0

I have an image upload script that works well on its own but fails when I try to run in via a PHP function that I was hoping would just keep the PHP file in the DIV

function Upload()
{
print'<div>';
include('../a/multi-image_uploader_thumbnail_creator.php');
print'</div>';
}

The PHP file runs well but once a user submits it leaves the PP function completely. The form code is:

    while($i++ < $upload_image_limit){
    $form_img .= '<label>Image '.$i.': </label> <input type="file" name="uplimg'.$i.'"><br />';
}

$htmo .= '
    <p>'.$feedback.'</p>
    <form method="post" enctype="multipart/form-data">
        '.$form_img.' <br />
        <input type="submit" value="Upload Images!" style="margin-left: 50px;" />
    </form>
    ';  

echo $htmo;
Steven Vanerp
  • 39
  • 1
  • 1
  • 7
  • 3
    do you know that php is server-side and javascript is cliente-side? I need to ask. Btw, why do you close the php tags before your include? – Sergio Dec 13 '13 at 23:05
  • @Sergio I think the answer to the 2nd question is because he didn't know the right answer to the 1st. – Barmar Dec 13 '13 at 23:09
  • 1
    You have some code issues... those aside, it sounds like what you want to do is run this in an iframe so the page doesn't refresh? Not the greatest idea, but it will probably then do what you want. – Mattt Dec 13 '13 at 23:10
  • Yes and thanks for the catch on the PHP closure. I edited the change. I have tried to find a JS solution but cannot find one to encompass a multipart form like this. Goal is that the user can select up to nine images to upload to my server. When they submit the selections, the page will confirm the upload and offer fresh chance to upload. The 'multi-image_uploader_thumbnail_creator.php' script does the when run solo but fails when run in the DIV – Steven Vanerp Dec 13 '13 at 23:13

1 Answers1

0

Your include() statement is outside of PHP. You shouldn't be ?> and <?phping around it. It's a PHP function.

Also, why are you using .= if you didn't define the variable before? You can just use =.

You should consider using templates, too, but that's a bit further down the road.


Edit: Try looking at the answer to this question or this other question to send images via AJAX.

Community
  • 1
  • 1
randak
  • 1,941
  • 1
  • 12
  • 22
  • I fixed the include() issue. The .= is how the original script was written and I have not completely modified it to my means since its not working up to what I need as of yet – Steven Vanerp Dec 13 '13 at 23:15
  • What is still not working, then? What are you hoping to achieve? I am having trouble understanding exactly what is and isn't showing, and when. – randak Dec 13 '13 at 23:17
  • When the user hits submit, the script jumps to my index page instead of staying in the DIV as I had hoped – Steven Vanerp Dec 13 '13 at 23:22
  • What does "stay inside the DIV" mean? If you don't want to reload the page when the user submits the form, you'll need to use AJAX. Otherwise, I'm not really sure what you want. – randak Dec 13 '13 at 23:23
  • I understand that as well. But I cannot find an ajax example that handles multipart data. The form could be for 1-9 images to upload – Steven Vanerp Dec 13 '13 at 23:27