Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Image upload in PHP
<?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'];
}
}
?>
<tr>
<td class="key">Image</td>
<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"/>
</td>
</tr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment