Jump to content

MadsK

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Everything posted by MadsK

  1. I think I've might have worked it out by putting {} around the if statement of the templateProcess function Thanks for looking though
  2. Hello guys, We are creating a system at work, which is going to do some creating/editing/retrieving of indesign templates. We are working with PHP OOP, and this is my first time working with OOP, which is why I think I'm running in to some problems. In our create template script, the "functions" inside the class are supposed to create directories, which corresponds to the name given to the template and the upload the indesign file (and an xml file that holds data) to a subdirectory called indesign (and a subdirectory called xml), which was created together with the main directory (The name of the template). I'm using the move_uploaded_file function to move the tmp files to their respective folders, but when creating the templates I get this errors: Warning: move_uploaded_file(../uploads/Test 2/indesign/Untitled-1.indd) [function.move-uploaded-file]: failed to open stream: No such file or directory in /var/www/html/web2inprint/classes/actions.class.php on line 406 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpbHyk4v' to '../uploads/Test 2/indesign/Untitled-1.indd' in /var/www/html/web2inprint/classes/actions.class.php on line 406 Warning: move_uploaded_file(../uploads/Test 2/xml/test.xml) [function.move-uploaded-file]: failed to open stream: No such file or directory in /var/www/html/web2inprint/classes/actions.class.php on line 407 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpKjATmu' to '../uploads/Test 2/xml/test.xml' in /var/www/html/web2inprint/classes/actions.class.php on line 407 However here comes the strange thing. It actually works. The files are uploaded and placed in their sub directories. Yet I still get this error. Here is the class class templateActions extends base{ private $templatename; private $templatedescription; private $templatepath; private $templateindesign; private $templatexml; private $errors; private $templatedir; public function __construct() { $this->errors = array(); } public function templateVars() { $this->templatename = $_POST['templatename']; $this->templatedescription = $_POST['templatedescription']; $this->tempalteindesign = $_FILES['templatefiles']['name']['0']; $this->templatexml = $_FILES['templatefiles']['name']['1']; $this->templatedir = '../uploads/'.$_POST['templatename']; } public function templateProcess() { if($this->validTemplateData()) $this->createDir(); $this->uploadTemplate(); $this->createTemplate(); return count($this->errors) ? 0 : 1; } private function templateExists() { $this->dbconnect(); $data = mysql_query("SELECT skabelonnavn FROM skabelon WHERE skabelonnavn = '{$this->templatename}'"); return (mysql_num_rows($data) > 0)? 1 : 0; } public function showErrors() { return ($this->errors); } private function validTemplateData() { if($this->templateExists()) $this->errors['templatename'] = 'Templatenavn er i brug'; if(empty($this->templatename)) $this->errors['templatename'] = 'Templatenavn mangler'; if(empty($this->templatedescription)) $this->errors['templatedescription'] = 'Template beskrivelse mangler'; if($this->uploadTemplate()) $this->errors['upload'] = 'Fejl under upload'; return count($this->errors) ? 0 : 1; } private function createDir() { mkdir($this->templatedir,0777); mkdir($this->templatedir.'/indesign',0777); mkdir($this->templatedir.'/xml',0777); mkdir($this->templatedir.'/tryk',0777); chmod($this->templatedir,0777); chmod($this->templatedir.'/indesign',0777); chmod($this->templatedir.'/xml',0777); chmod($this->templatedir.'/tryk',0777); } private function uploadTemplate() { move_uploaded_file($_FILES['templatefiles']['tmp_name'][0], $this->templatedir.'/indesign/'.$_FILES['templatefiles']['name'][0]); move_uploaded_file($_FILES['templatefiles']['tmp_name'][1], $this->templatedir.'/xml/'.$_FILES['templatefiles']['name'][1]); } private function createTemplate() { $this->dbconnect(); mysql_query("INSERT INTO skabelon (skabelonnavn, skabelonbeskrivelse, skabelonsti) VALUES ( '{$this->templatename}', '{$this->templatedescription}', '/{$this->templatename}/' )"); if(mysql_affected_rows() < 1) $this->errors['upload'] = 'Kunne ikke oprette bruger'; } } And here is the createtemplate.php file <?php $pageTitle = 'Admin - Opret Skabelon'; $dir = $_SERVER['DOCUMENT_ROOT'] . '/web2inprint/'; require_once($dir . 'includes/header.php'); require_once($dir .'classes/actions.class.php'); require_once($dir .'classes/access.class.php'); session_start(); $login = new login(); $registertemplate = new templateActions(); if ($login->isLoggedIn() && $login->isSuperUser()){ } else { header('location: ../index.php'); } if (isset($_POST['submitted']) && ($_GET['id'] == hash('SHA512', superUser))) { $registertemplate->templateVars(); if ($registertemplate->templateProcess()) { echo 'Skabelonen er oprettet'; } else { $fejl = $registertemplate->showErrors(); } } ?> <?php echo $fejl['upload']; ?> <form enctype="multipart/form-data" id="createTemplate" method="post" action="<?php echo $_SERVER['PHP_SELF']."?id=". hash('SHA512', superUser); ?>"> <fieldset> <legend>Opret Skabelon</legend> <p><label>Skabelon Navn</label> <input type="text" name="templatename" value="<?php if (isset($_POST['templatename'])) echo $_POST['templatename'] ?>" onChange="changevalue(this.value)"/> <?php echo $fejl['templatename'];?></p> <p><label>Skabelon Beskrivelse</label> <input type="text" name="templatedescription" value="<?php if (isset($_POST['templatedescription'])) echo $_POST['templatedescription'] ?>" /> <?php echo $fejl['templatedescription'];?></p> <p><label>Skabelon InDesign</label> <input type="file" id="templateindesign" name="templatefiles[]" onchange="checkFileIndesign(this.value)" /> <?php echo $fejl['templateindesign'];?></p> <p><label>Skabelon XML</label> <input type="file" id="templatexml" name="templatefiles[]" onchange="checkFileXml(this.value)"/> <?php echo $fejl['templatexml'];?></p> <input type="submit" name="submit" value="Opret Skabelon" /> <input type="hidden" value="TRUE" name="submitted" /> </fieldset> </form> <script type="text/javascript"> function checkFileIndesign(filename) { if(filename.lastIndexOf(".indd")==-1) { alert("Vælg en Indesign fil"); return false; } } function checkFileXml(filename) { if(filename.lastIndexOf(".xml")==-1) { alert("Vælg en XML fil"); return false; } } </script>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.