elis Posted September 4, 2008 Share Posted September 4, 2008 I'm editing a script another programmer wrote to upload more than one document, however, the script is assuming that a previous document has already been uploaded. When that's the case (there's already a previous document uploaded) the script executes correctly. However, when there's no previous document (i.e. it's the first upload) the script won't execute, instead the page just refreshes. I've tried going through the script multiple times to locate the problem myself, however PDOs are not my strong point and its likely I glanced over it. If someone could act as a second pair of eyes and point me in the right direction it would be greatly appreciated. Here is the full upload script: <?php /* * attachment.php: Attach a resume to a candidate */ require_once 'startups.php'; if(! $session->get('s_isLoggedIn')) { redirect('/index.php', $_SERVER['REQUEST_URI']); } if(isset($_POST["attach_doc"])) { $id=$_GET['id']; if (is_uploaded_file($_FILES['resume_doc']['tmp_name'])){ $resume_doc = fopen($_FILES['resume_doc']['tmp_name'], 'rb'); $resume_filetype = $_FILES['resume_doc']['type']; }else { $resume_doc = null; $resume_filetype = null; } $qry = "CALL addAttachment(:resume_doc, :resume_filetype, :resume_filename, :id)"; $conn->open(); $stmt = $conn->prepare($qry); $conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); $stmt->bindParam(':resume_doc', $resume_doc, PDO::PARAM_LOB); $stmt->bindParam(':resume_filetype', $resume_filetype, PDO::PARAM_STR); $stmt->bindParam(':resume_filename', $_FILES['resume_doc']['name']); $stmt->bindParam(':id', $id, PDO::PARAM_INT); $stmt->execute(); ?> <html> <head> <script> self.parent.tb_remove(); self.parent.location.reload(); </script> </head> </html> <? } else { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Resume Attchment</title> </head> <body bgcolor="#F2F2E3"> <fieldset> <legend style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9px">Please locate the file</legend> <form action="attachment.php?id=<?=$_GET['id']?>" method="post" enctype="multipart/form-data" onsubmit=""> <table> <tr> <td><label style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9px">Resume:</label></td><td align="left"><input type="file" size="30" name="resume_doc" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9px"/></td> </tr> <tr> <td></td> <td align="left"><input style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9px" type="submit" value="Attach Document" onclick="if(forms[0].resume_doc.value==''){alert('Please locate the file'); return false;}" name="attach_doc"/></td> </tr> </table> </form> </fieldset> </body> </html> <? } ?> If anything in the code needs clarifying, please let me know. Link to comment https://forums.phpfreaks.com/topic/122732-cant-upload-if-no-previous-file-exists-phppdo/ Share on other sites More sharing options...
elis Posted September 4, 2008 Author Share Posted September 4, 2008 A quick harmless bump. Link to comment https://forums.phpfreaks.com/topic/122732-cant-upload-if-no-previous-file-exists-phppdo/#findComment-634020 Share on other sites More sharing options...
grimmier Posted September 6, 2008 Share Posted September 6, 2008 try commenting out the else part of your if is uploaded statement I think its just setting everything to null if the file wasn't already uploaded. /* }else { $resume_doc = null; $resume_filetype = null; */ Link to comment https://forums.phpfreaks.com/topic/122732-cant-upload-if-no-previous-file-exists-phppdo/#findComment-634985 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.