├── smarty_temp
└── templates
│ ├── error.tpl
│ └── index.tpl
├── README.md
├── classes
├── files.class.php
└── ConnectSmarty.class.php
└── index.php
/smarty_temp/templates/error.tpl:
--------------------------------------------------------------------------------
1 |
2 |
3 | {$errmessage}
4 |
5 |
--------------------------------------------------------------------------------
/smarty_temp/templates/index.tpl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Homepage : File Upload
5 |
6 |
7 |
8 |
9 | {$success}
10 | {$error}
11 |
12 | Upload Logo
13 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # File upload in PEAR and Smarty
2 |
3 | Blog Article: [File upload in PEAR and Smarty](http://blog.chapagain.com.np/file-upload-in-pear-and-smarty/)
4 |
5 | #### Note on Smarty
6 |
7 | Smarty library files are not included here.
8 |
9 | You need to download Smarty library files from http://www.smarty.net/download
10 |
11 | Extract the file and rename the extracted folder as `smarty`
12 |
13 | Copy the folder `smarty` in your working directory.
14 |
15 | The directory structure should be as follows:
16 |
17 | my-folder (your working directory)
18 |
19 | -- classes (this contains class files)
20 |
21 | -- smarty (this is the Smarty library files directory)
22 |
23 | -- smarty_temp
24 |
25 |
--------------------------------------------------------------------------------
/classes/files.class.php:
--------------------------------------------------------------------------------
1 | getFiles($field_name);
10 |
11 | if ($file->isValid())
12 | {
13 | $moved = $file->moveTo("$dest/");
14 | if (PEAR::isError($moved))
15 | {
16 | require_once('ConnectSmarty.class.php');
17 | // create an object of the class included above
18 | $smarty = new ConnectSmarty;
19 |
20 | $error =& $moved->getMessage();
21 |
22 | // assign error message
23 | $smarty->assign('errmessage',$error);
24 |
25 | // display error message and exit
26 | $smarty->display('error.tpl');
27 | exit();
28 | }
29 | }
30 | }
31 | }
32 | ?>
--------------------------------------------------------------------------------
/classes/ConnectSmarty.class.php:
--------------------------------------------------------------------------------
1 | Smarty();
29 |
30 | $this->template_dir = 'smarty_temp/templates';
31 | $this->config_dir = 'smarty_temp/configs';
32 | $this->cache_dir = 'smarty_temp/cache';
33 | $this->compile_dir = 'smarty_temp/templates_c';
34 | }
35 | }
36 |
37 | ?>
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | upload($fieldName,$dest);
29 |
30 | // assign success message
31 | $smarty->assign('success','File Uploaded Successfully');
32 | }
33 | else
34 | {
35 | // assign error message
36 | $smarty->assign('error','Only jpge and gif image are supported.');
37 |
38 | // display error message and exit
39 | $smarty->display('index.tpl');
40 | exit();
41 | }
42 | }
43 |
44 | // display the content
45 | $smarty->display('index.tpl');
46 |
47 | ?>
--------------------------------------------------------------------------------