Jump to content

Browse and upload a file


ccorlett7

Recommended Posts

Hi guys,

 

I've created some coding and a button allowing the user to browse their local machine and upload a file, with certain details then displayed on a new web page.

 

Is there a way I can get the ouput to display on a popup window rather than navigate to a new browser page?

 

The code I have used to create this is:

 

 <form action="upload_file.php" method="post"
        enctype="multipart/form-data">
            <label for="file">Filename:</label>
            <input type="file" name="file" id="file" />
            
<input type="submit" name="submit" value="Start" style="height:50px" />
       </form> 

 

When the user clicks the 'start' button, the php script runs and retrieves the information required but I want this to be output on a popup window.

 

Cheers for your time

Link to comment
Share on other sites

cheers, that could be handy but I have it so the file uploads perfectly fine and when 'start; is clicked the php script gets the details. I just want these details displayed on a popup window rather than the web page changing to a blank one.

 

Do I embed a javascript window.open() somehow?

Link to comment
Share on other sites

You should be able to add in target="_blank" as an attribute in your form tag that should open a new window instead. From there you could use javascript (or js library of some sort) in your file upload_file.php to resize the window to the dimensions you want. I've done that in the past, but the only downside is if a user has javascript turned off you won't get the same effect for those people. I hope that helps!

 

-Frank

Link to comment
Share on other sites

thanks, ive used the target=_blank. Im now trying to assign the button a javascrip function to run involving

 

 myWindow.document.write(PHP SCRIPT.php) 

 

Is this possible? So that when clicked the button opens a new window and displays the results from my php file?

Link to comment
Share on other sites

I've done load of playing around now trying to get this working but still to no success.

 

I can create a popup using javascript and for it to run the php script, but this displays an error in my php script, evading the 'IF' statements and going straight to the final 'Else' echo statement.

 

Any ideas guys?

 

the code in my PHP script is

 

<?php
if ($_FILES["file"]["type"] == "image/jpeg")
{
    if ($_FILES["file"]["error"] > 0)
        {
            echo "Error: " . $_FILES["file"]["error"] . "<br />";
        }
    else
        {
            
            echo "Upload: " . $_FILES["file"]["name"] . "<br />";
            echo "Type: " . $_FILES["file"]["type"] . "<br />";
            echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
            echo "Stored in: " . $_FILES["file"]["tmp_name"];
        }
}
else
{
  echo "Invalid file. Please select a .JPG file.";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.