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
Related
I'm trying to upload a photo using the following code. Suppose I'm uploading "abc.gif". It uploads in the proper directory as "abc.jpg". But my question is does the file type actually change?
$file_name = $_FILES['input_name']['name'];
$file_tmp =$_FILES['input_name']['tmp_name'];
move_uploaded_file($file_tmp, "abc.jpg");
This piece of code works perfectly while uploading.
But while making a resized copy of this abc.jpg using—
imagecreatefromjpg("abc.jpg") & imagejpeg()
—it shows a black screen.
When I move the file using the extension .jpg, does the file type actually change? Why does this problem occur?
Please verify the your imagecreatefromjpg("abc.jpg") & imagejpeg() function work correctly, you say file move successfully and display correctly so issue in the this image operation function which convert image into black image.
Thanks.
I am using plupload to upload file in my php based website, with large file uploading the file becomes a file named 'blob' without any suffix. I know this is a binary file that contains the raw data, question is how to retrieve the data and save it back as an image file, say .png/.jpg or etc? I tried:
$imageString = file_get_contents($blogPath);
$image = imagecreatefromstring($imageString);
But it gives me some 'Data is not in recognized format...' error, any thoughts? Thanks in advance.
Your call to imagecreatefromstring() should work just fine if your file_get_contents() is working. Use var_dump($imageString) to verify. Did you mean to name your variable $blobPath instead of $blogPath?
You don't need to load this image though. Just rename the file.
rename($blobPath, 'new/path/here.jpg');
http://php.net/manual/en/function.rename.php
I am storing the uploaded image files for late use, like attaching them to posts or products(my site is e-commerce CMS). I figured that my image file didn't get fully uploaded to the server, the image before upload is 6mb, but the blob file is just 192kb, so my best guess is that what get uploaded is just a chunk instead of the whole package, and yet that brought up another question: how should I take all the pieces and assemble them as one complete image file? As mentioned earlier, I am using plupload for js plugin and php as backend, the backend php code to handle uploading goes like this:
move_uploaded_file($_FILES["file"]["tmp_name"], $uploadFolder . $_FILES["file"]["name"]);
Instead of doing that you should do this to display image to the browser
<img src="data:image/jpeg;base64,'.base64_encode( $row['blob_image'] ).'"/>
I'm not sure what imagecreatefromsting does or how it encodes the image.
I looked at the documentation for that function; you're missing:
$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data); <--- this operation
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";
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/
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.