It looks like you're new here. If you want to get involved, click one of these buttons!
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
//$fileTypes = str_replace('*.','',$_REQUEST['fileext']);
// $fileTypes = str_replace(';','|',$fileTypes);
// $typesArray = split('\|',$fileTypes);
$fileParts = pathinfo($_FILES['Filedata']['name']);
$fileExt = '.'.$fileParts['extension'];
// if (in_array($fileParts['extension'],$typesArray)) {
// Uncomment the following line if you want to make the directory if it doesn't exist
// mkdir(str_replace('//','/',$targetPath), 0755, true);
$tfn = 0;
while(is_file($targetFile)) {
$targetFile = str_ireplace($fileExt, '', $targetFile);
$targetFile = str_ireplace('['.$tfn.']', '', $targetFile);
$tfn++;
$targetFile = $targetFile.'['.$tfn.']'.$fileExt;
}
move_uploaded_file($tempFile,$targetFile);
echo \"1\";
// } else {
// echo 'Invalid file type.';
// }
}/* Uploadify v2.1.4 */
if (!empty($_FILES)) {
$name = reset(explode(".",$_FILES['Filedata']['name']));
$ext = end(explode(".",$_FILES['Filedata']['name']));
$filename = date('h:i:s A', strtotime('-1 hour'))." - ".$name.".".$ext;
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/' . date('Y.m-d') . '/';
$targetFile = str_replace('//','/',$targetPath) . $filename;
if (!file_exists ( $targetPath )) {
mkdir(str_replace('//','/',$targetPath), 0755, true);
move_uploaded_file($tempFile,$targetFile);
echo $filename;
} else {
move_uploaded_file($tempFile,$targetFile);
echo $filename;
}} else {
echo 'Invalid file type.';
}
?>strtotime('-1 hour') because our server is 1 hour ahead of us.
$('#fileUpload').uploadify({
...
'onComplete' : function(event, ID, fileObj, response, data) {
$('#formFieldID').val(response);
}
});
$('#fileUpload').uploadify({
...
'onUploadSuccess' : function(file, data, response) {
$('#formFieldID').val(response);
}
});
<?php
/* Uploadify v2.1.4 */
if (!empty($_FILES)) {
$name = reset(explode(".",$_FILES['Filedata']['name']));
$ext = end(explode(".",$_FILES['Filedata']['name']));
$filename = date('h:i:s A', strtotime('-1 hour'))." - ".$name.".".$ext;
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/' . date('Y.m-d') . '/';
$targetFile = str_replace('//','/',$targetPath) . $filename;
if (!file_exists ( $targetPath )) {
mkdir(str_replace('//','/',$targetPath), 0755, true);
move_uploaded_file($tempFile,$targetFile);
echo $filename;
} else {
move_uploaded_file($tempFile,$targetFile);
echo $filename;
}} else {
echo 'Invalid file type.';
}
?> $(function() {
$('#file_upload').uploadify({
'uploader' : 'incl/uploadify/uploadify.swf',
'script' : 'incl/uploadify/uploadify.php',
'cancelImg' : 'incl/uploadify/cancel.png',
'folder' : 'uploads/',
'method' : 'post',
'buttonText' : 'Browse',
'displayData' : 'percentage',
'fileExt' : '*.pdf',
'fileDesc' : 'Acrobat File (PDF)',
'queueSizeLimit': 10,
'sizeLimit' : 104857600,
'multi' : true,
'auto' : true,
'removeCompleted': false,
'onAllComplete' : function(event, queueID, fileObj, response, data) {
$('#status-message').text(data.filesUploaded + ' files uploaded, ' + data.errors + ' errors.');
},
'onComplete': function(event, queueID, fileObj, response, data) {
$('#uploaded_files').val($('#uploaded_files').val()+'<br/>'+response);
}
});
});
<input name="uploaded_files" id="uploaded_files" class="inputbox" type="hidden" />
beyerjonathan said: beyerjonathan August 12 Permalink Flag
I'm using the latest version of 2. What would be the full code that would allow the person to input a name, then upload the files, and then have those files saved in a subfolder using the name that they entered?
Thanks,
Jonathan