ccorlett7 Posted March 23, 2011 Share Posted March 23, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/231491-browse-and-upload-a-file/ Share on other sites More sharing options...
lbh2011 Posted March 23, 2011 Share Posted March 23, 2011 Could you explore using AJAX to keep all the information on the same page without having to reload it... then you wouldn't need to have a popup. Something like this may work for what you're trying to do: http://ajaxian.com/archives/asynchronous-file-upload-with-ajax-progress-bar-in-php Quote Link to comment https://forums.phpfreaks.com/topic/231491-browse-and-upload-a-file/#findComment-1191318 Share on other sites More sharing options...
ccorlett7 Posted March 23, 2011 Author Share Posted March 23, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/231491-browse-and-upload-a-file/#findComment-1191321 Share on other sites More sharing options...
WTFranklin Posted March 23, 2011 Share Posted March 23, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/231491-browse-and-upload-a-file/#findComment-1191323 Share on other sites More sharing options...
ccorlett7 Posted March 23, 2011 Author Share Posted March 23, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/231491-browse-and-upload-a-file/#findComment-1191330 Share on other sites More sharing options...
ccorlett7 Posted March 24, 2011 Author Share Posted March 24, 2011 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."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/231491-browse-and-upload-a-file/#findComment-1191706 Share on other sites More sharing options...
ccorlett7 Posted March 24, 2011 Author Share Posted March 24, 2011 further to my previous reply, the error displayed in the popup window says it is Line 2 of the PHP script. Quote Link to comment https://forums.phpfreaks.com/topic/231491-browse-and-upload-a-file/#findComment-1191755 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.