PHP උදවුවක් ඕනේ ඉක්මනට
මම් PHP වලින් image upload එකක් හැදුවා ඒත් upload වෙන්නෙ නෑ මම දීලා තියෙන තැනට පුලුවන්නම් උදවු කරනවද? මේ තියෙන්නේ code එක
script එක
<script>
$(function() {
$('#file_upload').uploadify({
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php',
'folder' : '../uploads/',
'multi' : false
// Put your options here
});
});
</script>
uploadify.php , File එක
$targetFolder = '../uploads/'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT']. $targetFolder;
$targetFile = rtrim($targetPath,'//') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
මම් PHP වලින් image upload එකක් හැදුවා ඒත් upload වෙන්නෙ නෑ මම දීලා තියෙන තැනට පුලුවන්නම් උදවු කරනවද? මේ තියෙන්නේ code එක
script එක
<script>
$(function() {
$('#file_upload').uploadify({
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php',
'folder' : '../uploads/',
'multi' : false
// Put your options here
});
});
</script>
uploadify.php , File එක
$targetFolder = '../uploads/'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT']. $targetFolder;
$targetFile = rtrim($targetPath,'//') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
