Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Image upload in PHP
function save($category) {
$packageguide = JRequest::get( 'POST' );
$files = JRequest::get( 'FILES' );
if (isset($files['image_upload']) && !$files['image_upload']['error']) {
$dir = JPATH_ROOT.DS.'media'.DS.'packageguide'.DS.$category;
if(!file_exists($dir)) {
mkdir($dir, 0777, true);
move_uploaded_file($files['image_upload']['tmp_name'], $dir.DS.$files['image_upload']['name']);
$packageguide['image'] = DS.'media'.DS.'packageguide'.DS.$category.DS.$files['image_upload']['name'];
<td class="key">Image</td>
<?php if ($this->object->image): ?>
<img src="<?php print $this->object->image;?>" style="max-width:300px; margin:0 0 10px 0;" /><br style="clear:both" />
<?php endif; ?>
<input type="file" name="image_upload"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment