Using Upload component from HTML5 Builder Embarcadero
Upload is a submit enabled button on the form. But the documentation doesn't tell me where the actual file goes. When this function is called after the supposed successful upload all the names of the upload do come out. I can see the temp file name, file name, file size, etc in the memo box. But when I try this from HTML 5 Builder in Windows 10 or on the server the uploaded target file seems to be no where. I must be missing something.
function UploadClick($sender, $params)
{
//upload the file
$this->UploadStatus->Caption = 'BtnUploadClick ' . $this->Upload1->FileName;
$this->Memo1->AddLine('FileTmpName: ' . $this->Upload1->FileTmpName);
$this->Memo1->AddLine('FileName: ' . $this->Upload1->FileName);
$this->Memo1->AddLine('FileSize: ' . $this->Upload1->FileSize);
$this->Memo1->AddLine('FileType: ' . $this->Upload1->FileType);
$this->Memo1->AddLine('FileSubType : ' . $this->Upload1->FileSubType);
$this->Memo1->AddLine('GraphicWidth: ' . $this->Upload1->GraphicWidth);
$this->Memo1->AddLine('GraphicHeihgt: ' . $this->Upload1->GraphicHeight);
if($this->Upload1->isGIF ())
$tmp = ' is gif';
if($this->Upload1->isJPEG())
$tmp = ' is jpeg';
if($this->Upload1->isPNG())
$tmp = ' is png';
$this->Memo1->AddLine('File Ext: ' . $this->Upload1->FileExt . $tmp);
}
What is not shown in the example is you need to collect the file from the server temp directory and then place it where you want:
if(move_uploaded_file($this->Upload1->FileTmpName, $this->Upload1->FileName))
{
echo "File is valid, and was successfully uploaded.\n";
}
else
{
echo "Possible file upload attack!\n";
}
Just add to the previous code and the file is saved to the server at the script location.
Related
I'm converting images into different sizes using ImageMagick. The conversion works OK, but there are some files that are converted twice.
For example, i'm converting a filename rj54c124a4cb96b3.56843124.tif into jpg using the suffix small.
The conversion works OK but i'm getting two of the same, like so: rj54c124a4cb96b3.56843124_small-0.jpg and rj54c124a4cb96b3.56843124_small-1.jpg
It adds a number after the suffix! Why? Like i've said, out of 3000 files, it only does that to a couple.
EDIT:
As per Keith Thompson question, here's the script im using in PHP
$file = 'c:/website_gallery/rj54c124a4cb96b3.56843124.tif';
$output = 'c:/public_html/gallery/files/4/2/rj54c124a4cb96b3.56843124_small.jpg';
$operator = '-resize'; // in some cases i will use -thumbnail
$width = 125;
$height = 125;
$flag = '^>'; // for localhost; use \> for live host server
exec('convert' . ' ' . $file . ' ' . $operator . ' ' . $width . 'x' . $height . $flag . ' ' . $output, $debug, $return);
I am trying to let users record an audio file in a Phonegap app. It works well on Android, but on iOS I get the following error when the recording should start:
"Failed to start recording using AvAudioRecorder".
I use a .wav filename, I create the file first, I have followed all instructions I have found and I keep getting the error.
This is the piece of code:
theFileSystem.root.getFile(filename,{create:true},function(fileEntry){
mediaFileURL = fileEntry.toURL();
console.log('Created file ' + mediaFileURL);
mediaRec = new Media(mediaFileURL, function(){
//console.log('Media File created');
}, function(err){
alert('Error creating the media file: ' + err.message);
console.log(mediaFileURL);
for(k in err){
console.log(k + ': ' + err[k]);
}
stopRecordingFile();
});
mediaRec.startRecord();
},function(err){
alert("Error setting audio file");
});
I see the console message 'Created file ...' so the file is successfully created. Then I get the error.
Media plugin version is 0.2.11
I don't know what else to try. Thanks for any help.
I solved this myself.
I'll leave solution here in case it helps someone.
For iOS, this needs to be changed:
mediaFileURL = fileEntry.toURL();
to this:
mediaFileURL = fileEntry.fullPath;
Also, even though I was requesting the Persistent filesystem, iOS saved the file in the tmp folder. So to upload the file afterwards using FileTransfer, I used this to refer to the file (I tried different approaches and this was the one that worked):
sendFileURL = cordova.file.tempDirectory + filename;
following fix to the Url solved the problem for me.
fixFileName = mediaFiles[i].fullPath.indexOf('file://') > -1 ? mediaFiles[i].fullPath : "file://" + mediaFiles[i].fullPath;
ok. this creepy error was solved.
all i did was made the file extension to uppercase, i.e.
made ".wav" to ".WAV".
When I want to upload anything in any form I see the Warning: escapeshellarg() has been disabled for security reasons message on my site. What can I do to fix this?
My framework is codeigniter final version.
Here is the full warning:
A PHP Error was encountered
Severity: Warning
Message: escapeshellarg() has been disabled for security reasons
Filename: libraries/Upload.php
The # operator will silence any PHP errors the function could raise. You should never use it!
Solutions:
Remove the escapeshellarg string from the disable_functions in php.ini file
Ask your host provider to remove Remove the escapeshellarg string from the disable_functions in php.ini file if you don't have an access to the php.ini file
make your own escapeshellarg. The function only escapes any single quotes in the given string and then adds single quotes around it.
function my_escapeshellarg($input)
{
$input = str_replace('\'', '\\\'', $input);
return '\''.$input.'\'';
}
and do something like this:
// $cmd = 'file --brief --mime ' . escapeshellarg($file['tmp_name']) . ' 2>&1';
$cmd = 'file --brief --mime ' . my_escapeshellarg($file['tmp_name']) . ' 2>&1';
But what is best is to extend the Upload.php library and override the _file_mime_type function instead of changing on the core of CodeIgniter so that you will not lose it if you ever want to update CodeIgniter.
Helpful links: https://www.codeigniter.com/user_guide/general/core_classes.html
Try
$cmd = 'file --brief --mime ' . #escapeshellarg($file['tmp_name']) . ' 2>&1';
Open Upload.php file from system/libraries folder and put # in front of escapeshellarg($file['tmp_name']) at line 1066
and second thing upload this file under application/libraries folder that will be better, other wise no problem, you can replace system's Upload.php file.
Remove the escapeshellarg string from the disable_functions at php.ini* file
Ask your hosting provider to remove the string above if you don't have an access to the php.ini* file
Change hosting provider which allows the running of the escapeshellarg function.
from this website: http://www.2by2host.com/articles/php-errors-faq/disabled_escapeshellarg/
Another simple way to solve this issue is just move your application from development to production:
Open index.php in your application root and change
define('ENVIRONMENT', 'development');
to
define('ENVIRONMENT', 'production');
I have found some posts with the same problem I have, however, no solutions presented. I am not 100% sure what to make of this, but hope you can help.
I am attempting to use Uploadify to upload files, but the following happens:
Browse for file successful (hence my 'script' and 'uploaded' attributes are correct)
Progress bar says "100%" and completes.
onComplete fires saying upload successful (according to the path alerted, 'folder' attribute is correct.)
If I die my script before any output, the #3 step does not happen - hence it reaches the 'script' specified. After output, the script doesn't die.
FILE IS NOT FOUND IN FILESYSTEM
Not sure how this is possible - as far as I can tell, everything is correct.
Here is my code:
<script type="text/javascript">
$(document).ready(function() {
$("#addimage").validationEngine();
$('#imagefile').uploadify({
'uploader': "/js/uploadify/uploadify.swf",
'fileExt': "*.jpg;*.jpeg;*.png;*.gif",
'buttonText': "Browse...",
'script': "/js/uploadify/uploadify.php",
'cancelImg': "/js/uploadify/cancel.png",
'folder': "/uploads",
'fileDesc': 'Only *.jpg, *.jpeg, *.png, *.gif are allowed',
'auto': true,
'onComplete': function(event, ID, fileObj, response, data) {
$('#name').val('Please edit this text to add a description...');
alert('Uploaded ' + fileObj.name + ' to ' + fileObj.filePath + '.');
}
});
});
</script>
<input type="file" id="imagefile" name="imagefile" />
<?php
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//', '/', $targetPath) . 'image_' . date('YmdHis') . '_' . $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
}
?>
The PHP script's only change is the name of the targetFile which I have changed, to ensure some sort of unique filename (although not foolproof) but otherwise the script is the same as released (with comments removed here for brevity purposes).
Can anybody tell my why Uploadify indicates that the file upload was successful, but no file exists in the uploads directory? I am using Windows, PHP5.3, and the uploads folder is writable (I can upload files there without Uploadify, but not with it)
Thanks in advance!
Kobus
I had similar problems on a Linux machine. It turned out that the PHP configuration on my server was the cuplrit. PHP was running in SAFE MODE. As I had uploaded the Uploadify scripts via FTP, so script files were stored in the file system with my FTP user details. Since PHP's temp folder was owned by the server root, I had a UID mismatch, i.e. the temporary upload file was attributed to root while the upload script that tried to move it was owned by the FTP user. That fragged it.
To resolve this I changed the ownership of the uploadify php script to root and from there on it worked.
I am using the FCKEditor wysiwyg editor, and was wondering if anyone figured out how to use the absolute path instead of relative path after you add an image in the editor?
And if so, how.
Search for this code in fckeditor\editor\filemanager\browser\default\connectors\php\basexml.php:
echo '<CurrentFolder path="' . ConvertToXmlAttribute( $currentFolder ) . '" url="' . ConvertToXmlAttribute( GetUrlFromPath( $resourceType, $currentFolder ) ) . '" />' ;
Replace it with this:
echo '<CurrentFolder path="' . ConvertToXmlAttribute( $currentFolder ) . '" url="'.'http://www.YOURDOMAINHERE.com' .ConvertToXmlAttribute( GetUrlFromPath( $resourceType, $currentFolder ) ) . '" />' ;