Solved

popup to upload file and set session values?

Posted on 2012-03-10
2
282 Views
Last Modified: 2012-03-15
I would like to use a popup to upload a file and then to also
set $_SESSION values. These values should be saved after the
popup closes so that they can be used to fill fields in the main page.
The  popup, below, is not saving the $_SESSION values.
How can this be fixed?

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

 <?php
 if(!empty($_FILES) ){
$_SESSION['name']=$_FILES['in_file']['name'];  
echo  $_SESSION['name']; //for testing
}
?>  
   
</head>

<body>

<script language="javascript" type="text/javascript">

function popitup(url) {
      newwindow=window.open(url,'name','height=200,width=150');
      if (window.focus) {newwindow.focus()}
      return false;
}

</script>

<input type="file" name="in_file" id="in_file">
<input type="submit" name="submit">

</body>
</html>
0
Comment
Question by:pillmill
2 Comments
 
LVL 16

Expert Comment

by:Chris Harte
ID: 37704735
Even though it is a popup, it is still a separate page. You need to include the function session_start() as the first line of php in every page.

http://uk3.php.net/manual/en/function.session-start.php
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37705286
This script will not work, even if you put session_start() at the top of the PHP because it has the HTML wrapper above the start-PHP statement. That creates browser output.  Browser output cannot come before cookies.  The session handler uses cookies. Thud.

Can you describe your question in non-technical terms?  It seems like there may be a standard design pattern that will meet your needs, but it's kind of hard to understand from what I have seen so far.

Thanks and regards, ~Ray
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now