How I can uploads text files with HTML 5? - php

I have following problem. I use this tutorial to creating a multiple file uploader:
http://tutorialzine.com/2011/09/html5-file-upload-jquery-php/
But this code uploding only IMAGES. I want this code to upload text files, not images. Is there a possibility to happen.
In file script.js i changed a type of file with this code, but don't work.
// Called before each upload is started
beforeEach: function(file){
if(!value.match(/\.(txt)|(csv)$/)){
alert('Only TXT and CSV files!');
// Returning false will cause the
// file to be rejected
return false;
}
},
The error message after uploadied files is "Your browser does not support HTML5 file uploads!"
What changes should I make to work correctly?
Thanks in advace !

http://www.script-tutorials.com/pure-html5-file-upload/

Related

How to upload csv file by class.upload.php?

I am using upload php class from this site: http://www.verot.net/
Image upload is working fine. But when I try to upload csv file it throughs an error:
getimagesize(): Read error! [APP\Vendor\class.upload.php, line 2423]
Here is my code:
$upload = new Upload($file['file']);
$upload->no_script = false;
$upload->allowed = array('application/msword');
$upload->file_new_name_body = 'data';
$upload->process($this->target_path);
if (!$upload->processed) {
$msg = $this->generateError($upload->error);
$this->Session->setFlash($msg);
return $this->redirect($this->referer());
}
Here $file has the all info of attached file.
If I try to upload an image it works fine but when I try to upload a csv file it shows error. I set the mime-type. But no luck. Anyone have this experience. Or is there any plugin like verot.net to upload file. Any idea will be appreciated
This tutorial guides you trought file uploading process:
W3Schools: File Upload
File uploading is not very hard, so I suggest you to try learning it.
Hope this helps!
Your class file is meant to upload or resize image files only.
It will not work for other extensions like .csv, .txt or any other text file or non image file.
I was searching answer to your same question and got that this class should work fine with any other file upload . You just need to set the following for all files other than image
$upload->mime_getimagesize = false;
This will not throw the error you mentioned for non image files

Checking if the uploaded file is really a proper file or not (php)

Do the following steps to Understand the problem clearly :
Open notepad.
Type something and save it as " .png " (or any other image format).
Try to upload it as a image file with extension validation.
Now try to display it.
Expected : To show error while uploading
Actual : The file gets easily uploaded without any problem and error occurs only while accessing it.
mime_content_type() is deprecated function.
instead you can use
<?php
print_r(getimagesize("listing.png"));
?>
if this shows error then the file is invalid png file. If file is valid it returns an array of information.
Edit: This works if you are working with images only.

Multiple File Upload PHP Ajax

I am looking for a ajax php uploader to uploads multiple files , i found some but unfortunately they did not work successfully with IE because IE 7 & 8 did not support
HTML5.
Uploadify & Plupload works fine with flash in IE but they did not return anything after uploading the file.In response i want the modified file name because before uploading a file i will modify the file name.
Any help or suggestion would be highly appriciated.
Thanks
Gaurav
Please refer this link for multiple file uploads using uploadify php - file uploads using uploadify
and in that link(in uploadify.php) replace the line
$fna = $_FILES['Filedata']['name'];
with
$fna = "your modified new filename";

Getting a file from a form in Zend

I'm trying to upload a file to Amazon S3 using Zend. Everything is working except I can't get access to the file in the POST[] array.
Is there anyway I can easily take the file from the form. All the documentation examples only show you how to do this when uploading a file to your local file system.
It is quite straight forward once you get the hang of it.
$form->image->setDestination('path/to/images');
if($form->isValid($_POST)){
if($form->image->isUploaded()){
if($form->image->receive()){
// For example, get the filename of the upload
$filename = $form->image->getFilename();
}
} else {
// Not uploaded
}
} else {
// Not valid
}
Note that in my example image is the name of the upload element.
A small correction on the above it should be getFileName with a capital N.
$filename = $form->image->getFileName();
If you are uploading a file to your PHP script from a form, and then intend to upload that file to S3, you're looking in the wrong superglobal.
File uploads live in $_FILES, not $_POST. Check out the PHP documentation on handling file uploads for information on how to use it best.

How to save a snapshot of a SWF to the server with AS3?

I am facing the task of having to upload a snapshot to the server. But I don't want the user to download the image to their computer.
I have explored a few solutions of generating an image serverside with PHP, but they all seem to use a method where the server sends the image to the user.
See for instance: http://mattkenefick.com/blog/2008/11/06/saving-jpegs-with-flash/
I'm wondering if it's possible to save $GLOBALS["HTTP_RAW_POST_DATA"], which in that example contains the ByteArray sent by Flash, to the server as an image file....
Use php code that is along these lines to save the contents of $GLOBALS["HTTP_RAW_POST_DATA"]
// untested code
$imageBytes = $GLOBALS["HTTP_RAW_POST_DATA"]
// in real code you better create a new file for every upload :-)
$file = fopen("uploads/test.jpg", "w");
if(!fwrite($file, $imageBytes)){
return "Error writing to file: $file";
}
fclose($file);

Categories