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 pages, and session is working well, until reaching the last page (upload_process.php).
form.php - flname.php - upload.php - upload_process.php
(gather imput) - (create dir) - (upload files - form) - (upload process/display log)
here is my code for upload_process.php:
PHP 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="http://www.webmaster-talk.com/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 (using session), the page will show http 500 error.
i would appreciate if someone could help me out here. really need your help, thanks.
i will show the rest of the files if you need me to.
btw, i'm hosted on a linux machine.
thanks a lot.
|