php - Check if File exists before running a query -
i newbie forgive ignorance;
i have upload pdf form check if form exists, if doesnt, upload , therefore run mysql insert query. tried this:
if (file_exists($pdfsubdirectory.$filename)) if (isset($_post['submit'])) { $quer->execute(); }
but error;
> fatal error: call member function execute() on non-object
any ideas?
my main code is;
<?php require "config.php"; $cat = $_get['cat1']; $catid = $_get['cat']; $subcat = $_get['subcat']; $subcatid = $_get['subcatid']; $subcat2 = $_get['subcat2']; //form vars $form_class = $_post['class']; // create modify delete flag $form_cerfa = $_post['cerfa']; // cerfa yes or no flag $form_id = $_post['id']; $form_name = $_post['name']; $predir = "./docs"; $dir = $predir."/" .$cat. "/" .$subcat."/" .$subcat2 . "/"; $dir= strtolower($dir); $dir= str_replace(' ', '_', $dir); $myhtml1 = <<<eod <!doctype html> <html> <head> <title>$subcat / $subcat2</title> </head> <body> <table align="center" border="0" cellpadding="1" cellspacing="1" style="height: 100%; width: 100%;"> <tbody> <tr> <td> <table border="0" cellpadding="0" cellspacing="0" style="height: 100%; width: 100%;"> <tbody> <tr> <td style="width: 50%;"> <table border="0" cellpadding="0" cellspacing="0" style="width: 100%;"> <tbody> <tr> <td style="width: 50%;">you in category:</td> <td style="width: 50%;">$cat</td> </tr> <tr> <td>you in subcategory:</td> <td>$subcat</td> </tr> <tr> <td>you in section:</td> <td>$subcat2</td> </tr> </tbody> </table> </td> <td> <p>time:</p> <p>date:</p> </td> </tr> <tr> <td colspan="2"> <hr /> <p>...</p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> eod; echo $myhtml1; $pdfdirectory = $dir; $pdfsubdirectory = $pdfdirectory.$_post['class']."/"; $thumbdirectory = $pdfdirectory . "pdfimage/"; $filename = basename( $_files['pdf']['name'], ".pdf"); $filename = preg_replace("/[^a-za-z0-9_-]/", "", $filename).".pdf"; $thumb = basename($filename, ".pdf"); if (file_exists($pdfsubdirectory.$filename)) { echo "this file exists."; } else { if(move_uploaded_file($_files['pdf']['tmp_name'], $pdfsubdirectory.$filename)) { //the path pdf file $pdfwithpath = $pdfdirectory.$filename; $pdfwithsubpath = $pdfsubdirectory.$filename; $pdfwithpathimage = $pdfdirectory."pdfimage/"; $pdfwithpathimagethumb = $pdfwithpathimage.$thumb.".jpg"; //add desired extension thumbnail $thumb = $thumb.".jpg"; //execute imagemagick's 'convert', setting color space rgb , size 200px wide //exec("convert \"{$pdfwithsubpath}[0]\" -colorspace rgb -geometry 100 $thumbdirectory$thumb"); exec("convert -density 200 -page 792x612 \"{$pdfwithsubpath}[0]\" -append -resize 240 -background white -flatten +repage $thumbdirectory$thumb"); //show image echo "<p><a href=\"$pdfwithpath\"><img src=".$pdfwithpathimagethumb." alt=\"\" /></a></p>"; echo $pdfwithpathimagethumb; } } if (isset(file_exists($pdfsubdirectory.$filename))) { $quer->execute(); } ///////// start of query form addition////////// $quer = $dbo -> prepare("insert form_detail(form_id,form_name,form_category,form_subcategory,form_subcategory2,form_class,form_cerfa) values(:form_id,:form_name,:form_category,:form_subcategory,:form_subcategory2,:form_class,:form_cerfa)"); $quer ->bindparam(':form_id', $form_id); $quer ->bindparam(':form_name', $form_name); $quer ->bindparam(':form_category', $catid); $quer ->bindparam(':form_subcategory', $subcatid); $quer ->bindparam(':form_subcategory2', $subcat2); $quer ->bindparam(':form_class', $form_class); $quer ->bindparam(':form_cerfa', $form_cerfa); ///////////// end of query form addition//////////// $myhtml2 = <<<eod <form action="" method="post" enctype="multipart/form-data" name="myform"> <input type="file" name="pdf" /><br> <table border="0" cellpadding="0" cellspacing="0" style="width: 500px;"> <tbody> <tr> <td><label>cerfa : </label></td> <td><input type="radio" name="cerfa" value="1" checked="checked"/>yes<input type="radio" name="cerfa" value="0"/>no<br/></td> </tr> <tr> <td><label>form class: </label></td> <td><select name="class"> <option value="create">create</option> <option value="modify">modify</option> <option value="delete">delete</option> </select></td> </tr> <tr> <td> <label>form name: </label></td> <td><input type="text" name="name" value="name"/><br></td> </tr> <tr> <td><label>form reference no : </label></td> <td><input type="text" name="id" value="reference number"/></td> </tr> <tr> <td>check details , upload</td> <td><input type="submit" name="submit" value="upload"/></td> </tr> </tbody> </table> </form> <table border="0" cellpadding="0" cellspacing="0" style="width: 937px;"> <tbody> <tr> <td colspan="2"> <p>forms available</p> </td> </tr> </tbody> </table> <table border="1" cellpadding="0" cellspacing="0" style="height: 44px; width: 100%;"> <tbody> <tr> <td style="vertical-align: middle; width: 228px;">ref</td> <td rowspan="1" style="vertical-align: middle; width: 89px;">cerfa</td> <td colspan="3" rowspan="1" style="vertical-align: middle; width: 595px;">name</td> </tr> <tr> <td style="vertical-align: middle; width: 228px;"> </td> <td rowspan="1" style="text-align: center; vertical-align: middle;"> </td> <td colspan="3" rowspan="1" style="text-align: center; vertical-align: middle;"> </td> </tr> </tbody> </table> <p> </p> </body> </html> eod; echo $myhtml2; $it = new recursiveiteratoriterator(new recursivedirectoryiterator($dir."create/")); while($it->valid()) { if (!$it->isdot()) { echo 'file name: ' . $it->getsubpathname() . "\n<br>"; } $it->next(); } ?>
you need prepare $quer
before executing it. put code...
///////// start of query form addition////////// $quer = $dbo -> prepare("insert form_detail(form_id,form_name,form_category,form_subcategory,form_subcategory2,form_class,form_cerfa) values(:form_id,:form_name,:form_category,:form_subcategory,:form_subcategory2,:form_class,:form_cerfa)"); $quer ->bindparam(':form_id', $form_id); $quer ->bindparam(':form_name', $form_name); $quer ->bindparam(':form_category', $catid); $quer ->bindparam(':form_subcategory', $subcatid); $quer ->bindparam(':form_subcategory2', $subcat2); $quer ->bindparam(':form_class', $form_class); $quer ->bindparam(':form_cerfa', $form_cerfa); ///////////// end of query form addition////////////
above this:
if (file_exists($pdfsubdirectory.$filename)) if (isset($_post['submit'])) { $quer->execute(); }
when script ran, gets if (file_exists($pdfsubdirectory.$filename))
, finds true, , tries execute query doesn't exist.
Comments
Post a Comment