superkingkong Posted November 16, 2008 Share Posted November 16, 2008 hi guys, I'm just a newbie in php, trying to create an upload script. it was working initially, until i start using session, so that i can pass values between pages. i have few question, but let me start with this first. here is my code: <?php // this starts the session session_start(); $success = 0; $fail = 0; $uploaddir = 'chenup/'; $max_size = "10000000"; // 50000 is the same as 50kb $totalfiles = "5"; session_start(); require('includes/application_top.php'); echo '<html ' . HTML_PARAMS . '><head><meta http-equiv="Content-Type" content="text/html; charset=' . CHARSET . '">'; echo '<title>' . TITLE . ' - Upload Photos</title>'; echo '<base href="' . (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG . '">'; echo '<link rel="stylesheet" type="text/css" href="stylesheet.css"></head>'; echo '<body><center><table class="infoBoxContents" border="0" width="100%" cellspacing="0" cellpadding="0"><tr class="infoBoxContents"><td class="infoBoxContents" align="center"><table class="infoBoxContents" border="0" width="90%" cellspacing="8" cellpadding="8">'; for ($i=0;$i<$totalfiles;$i++) { if($_FILES['userfile']['name'][$i]) { $uploadfile = $uploaddir . basename($_FILES['userfile']['name'][$i]); $ext = strtolower(substr($uploadfile,strlen($uploadfile)-3,3)); if (preg_match("/(jpg|gif|png|tif|pdf)/",$ext)) { // Check File Size if(($_FILES['userfile']['size'][$i] < $_POST['MAX_FILE_SIZE']) || ($_FILES['userfile']['size'][$i] < $max_size)) { if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile)) { $success++; $success_total++; echo '<tr><td class="UploadPage" align="center"><b><font color="#00CC00">Upload Success !</font></b><br>' . ' <b>' . $_FILES['userfile']['name'][$i] . '</b> (' . $_FILES['userfile']['size'][$i]/1024 . ' kb)'; echo '</td></tr>'; } else { $fail++; echo '<tr><td class="UploadPage" align="center"><b><font color="#ff0000">Upload Failed.! Please retry</font></b><br>' . ' <b>' . $_FILES['userfile']['name'][$i] . '</b> (' . $_FILES['userfile']['size'][$i]/1024 . ' kb)'; echo '</td></tr>'; } } else { $fail++; echo '<tr><td class="UploadPage" align="center"><b><font color="#ff0000">Upload Failed ! File size exceed 10MB</font></b><br>' . ' <b>' . $_FILES['userfile']['name'][$i] . '</b> (' . $_FILES['userfile']['size'][$i]/1024 . ' kb)'; echo '</td></tr>'; } } else { $fail++; echo '<tr><td class="UploadPage" align="center"><b><font color="#ff0000">Upload Failed ! Invalid File Extension</font></b><br>' . ' <b>' . $_FILES['userfile']['name'][$i] . '</b> (' . $_FILES['userfile']['size'][$i]/1024 . ' kb)'; echo '</td></tr>'; } } } echo '</table></td></tr><tr><td class="main" align="center"> <br><table class="infoBoxContents" border="2" width="40%" cellspacing="3" cellpadding="3"><tr><td class="main" align=left>'; echo '<b>Total number of files uploaded:</b></td><td class="main" align=left> '.$success; echo '</td></tr><tr><td class="main" align=left><b>Total number of files not uploaded:</b></td><td class="main" align=left> '.$fail . '</td></tr></table></td></tr>'; echo '<tr><td class="main" align="center"> <br><form method="post"><input type="button" value="Close Window" onclick="window.close()"></form> <FORM METHOD="LINK" ACTION="upload.php"><INPUT TYPE="submit" VALUE="Continue"></FORM></td></tr>'; echo '<tr class="infoBoxContents"><td class="main" align="center"> <p><img src="images/store_logo.png" alt="PicsWorld"> <br><font size=-2>Copyright © 2008 <a href="http://picsworld.biz/">PicsWorld</a></font></td></tr></table>'; ?> The php script will be working if i remark // the session start (). when i unremark it, the page will show http 500 error. i would appreciate if someone could help me out here. really need your help, thanks. btw, i have few files before this final scripts. i will show it here if you need me to. thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/132985-problem-with-session-error-http-500-please-help/ Share on other sites More sharing options...
Mchl Posted November 16, 2008 Share Posted November 16, 2008 You should check how sessions are configured on your php.ini file. For example might not have writing rights to the folder where sessions are to be stored. Quote Link to comment https://forums.phpfreaks.com/topic/132985-problem-with-session-error-http-500-please-help/#findComment-691593 Share on other sites More sharing options...
.josh Posted November 16, 2008 Share Posted November 16, 2008 do you have cpanel or something equivelent? go to your error log, what does it say? Quote Link to comment https://forums.phpfreaks.com/topic/132985-problem-with-session-error-http-500-please-help/#findComment-691597 Share on other sites More sharing options...
superkingkong Posted November 16, 2008 Author Share Posted November 16, 2008 well, i'm not sure how my php.ini is. ok, my whole objective is to create a sub-folder within my upload folder, based on their first name and last name. so that they can upload files onto "their own" folder, easy for me to manage. probably my logic wrong.. since i'm not a programmer anyway, my first page is to get users' first and last name. form.php <?php // This is form.php ?> <html> <head><title>Photos Upload</title></head> <body> <center><p><br><br> <form method="post" action="fl_name.php"> Please enter your First Name: <input type="text" name="firstName" /> <p> Please enter your Last Name: <input type="text" name="lastName" /><p> <input type="submit" value="Submit" /> </form> </center> </body> </html> form.php is working to my expectation. second, form output to fl_name.php <?php // this starts the session session_start(); $firstname = $_POST['firstName']; $lastname = $_POST['lastName']; $fdate = date("Ymd_H:i:s", time()); $path = $fdate . "_" . $firstname . "_" . $lastname; // this sets variables in the session $_SESSION['fpath'] = $path; if ($firstname == '') { echo "<center><p>Please enter your first name."; echo "<p><FORM METHOD='LINK' ACTION='form.php'><INPUT TYPE='submit' VALUE='Back'></FORM></center>"; } elseif ($lastname == '') { echo "<center><p>Please enter your last name."; echo "<p><FORM METHOD='LINK' ACTION='form.php'><INPUT TYPE='submit' VALUE='Back'></FORM></center>"; } else { $oldumask = umask(0); $cf = @mkdir("chenup/" . $path,0777); umask($oldumask); if ($cf) { echo "<center><p>Please click <FORM METHOD='LINK' ACTION='upload.php'><INPUT TYPE='submit' VALUE='Continue'></FORM></center>"; // check session variable echo "Dir is " . $_SESSION['fpath']; } else { echo "<center><p>An error has occurred while attempting to validate your name. "; echo "<p>Please click <FORM METHOD='LINK' ACTION='form.php'><INPUT TYPE='submit' VALUE='Back'></FORM> to re-enter your name again.</center>"; } } ?> fl_name.php is working, since it manages to create directory and display the session variable - fpath third, is the upload.php <?php // this starts the session session_start(); require('includes/application_top.php'); ?> <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html <?php echo HTML_PARAMS; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> <title><?php echo TITLE; ?> - Upload Photos</title> <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>"> <link rel="stylesheet" type="text/css" href="stylesheet.css"> </head> <body> <center> <table border="0" width="100%" height="410" cellspacing="0" cellpadding="0" class="infoBox" width="660"> <tr class="infoBoxContents"><td class="main" align=center><p><br> <?php $numuploads = 5; $count = 1; ?> <form enctype="multipart/form-data" action="upload_process.php" method="post"> <?php while ($count <= $numuploads) { ?> Image <?php echo $count; ?> <input name="userfile[]" type="file" /><br /> <?php $count = $count + 1; } ?> <br> <input type="submit" value="Upload" /> </td></tr> <tr class="infoBoxContents"> <td class="main" align="center"> <table border="0" width="80%" cellspacing="0" cellpadding="0" class="infoBox"><tr class="infoBoxContents"><td class="main" align="left"> <p><br><ul><li>You can upload five (5) files at one time. <li>Please bear in mind that uploading of large size files will be slow. It is dependant on your internet connection. <li>Please rename your photos based on your firstname & lastname followed by a sequential number starting at 1. (Eg: benjohnson1.jpg, benjohnson2.jpg, etc) <li>Upload only in <b>jpg</b>, <b>gif</b>, <b>png</b>, <b>tif</b> or <b>pdf</b> format. Other file extentions will not be accepted. <li>Size: Maximum file size per photo is <b>10MB</b> (10,000KB). <li>Photo Resolution: The bigger the resolution of the photo, the better printout quality you will get.</ul> <li><?php echo "Dir is " . $_SESSION['fpath']; ?> <center>Please refer to <a href="http://www.microsoft.com/windowsxp/using/digitalphotography/learnmore/bestquality.mspx" target="_blank">http://www.microsoft.com/windowsxp/using/digitalphotography/learnmore/bestquality.mspx</a></center> </td></tr></table> </td> </tr> <tr class="infoBoxContents"> <td class="main" align="center"> <p><br><img src="images/store_logo.png" alt="PicsWorld"> <br><font size=1>Copyright © 2008 <a href="http://picsworld.biz/">PicsWorld</a></font> </td></tr></table> </form></center></body></html> upload.php is working as well, i mean, it still prints out the correct session variable Quote Link to comment https://forums.phpfreaks.com/topic/132985-problem-with-session-error-http-500-please-help/#findComment-691599 Share on other sites More sharing options...
superkingkong Posted November 16, 2008 Author Share Posted November 16, 2008 do you have cpanel or something equivelent? go to your error log, what does it say? yes, my account came with a cpanel, assigned to me by the hosting company. but i can't access it now, my office blocked the port i will check it when i reach home. so, where can i find the error log? can i check it with ftp? i have ftp access to my account now. Quote Link to comment https://forums.phpfreaks.com/topic/132985-problem-with-session-error-http-500-please-help/#findComment-691601 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.