Please anyone help me how to solve the following requirement using javascript and php.
when user upload(multiple file) any document we need to save that on the server, folder naming convention will be based on Year of date of birth (YYYY) and inside that (YYYY) folder will be a subfolder based on (MM) and then (DD) and then will be user Last name and inside that will be user first name. User will select type of the document i.e. assume "X, Y and Z"(Assume dropdown).
Create the file name on the server(Replace all the spaces with '~' and '/' with '!=')(File name will be yyyymmdd_lastname_firstname_documenttype.filetype), if a file already exists with same name use number(1,2,3,….) at the end.
e..g if a User Andy Walkar's dob is July 2 1979 document xyz.pdf is uploaded. His file name on the server will be "1979_07_02_walkar_andy_X~.pdf" and file will be uploaded on in the folder "Docs\YYYY\MM\DD\LastName\FirstName"
I am able to do single file upload into a server folder which is already exists on the server. But I am unable to implement mutiple file upload in to a dynamic folder structure. Thanks in advance.
Sorry for my english.
We are here to provide solutions to problems, not write all your code for you. That being said, a great solution to your problem is a jQuery plugin called Uploadify.
Uploadify is a jQuery plugin that integrates a fully-customizable multiple file upload utility on your website. It uses a mixture of Javascript, ActionScript, and any server-side language to dynamically create an instance over any DOM element on a page.
I tried Uploadify, but UI customization was difficult.
So My choice is fancyupload
another good file uploader lib.
You can manipulate uploaded file name with your php code.
and can customize your UI easily.
FancyUpload is a file-input replacement which features an unobtrusive,
multiple-file selection menu and queued upload with an animated
progress bar. It is easy to setup, is server independent, completely
styleable via CSS and XHTML and uses MooTools to work in all
Related
i created PHP form for my site, with image upload option on it.
but it only show the image name before image submitted, but i want to view/preview the image/file before submit so how this possible in this?
"file36":{"label":"Select/Upload a Student's Photo","accept":"jpg|jpeg|png|gif|bmt","files":true,"attach":true,"database":true,"maxbytes":204800,"fieldtype":"fileupload","required":true,}},
As far as I know this is not possible with php until you upload the image.
However, you are able to do so with jquery.
Check out http://blueimp.github.io/jQuery-File-Upload/
The old way is to upload the image to a temp folder, create an iframe and load the response there. Then link the temp image from the iframe to a hidden field in the final form with JavaScript. When you submit the form place the image in the right folder. Finally run a cron job every 24-48h to empty out the temp folder.
The new way is the File API supported in IE10+ and all modern browsers. Fallbacks in Flash and Silverlight exist for older browsers.
You obviously misunderstand how file uploads w/ PHP work.
PHP is server side programming language, meaning, it can only execute and access scripts, that are on the server. So, for PHP to access / analyze a picture in any way, it has to be on the server already.
You can upload the file in a temporary directory, analyze it and, if it suits your needs, move to a permanent folder. Otherwise, just delete it.
Suppose we have the web application which handle create, read, update and delete articles and each article should have gallery of images. I have to make one to one relation between Article and Gallery and one to many relation between Gallery and Media.
HTML5 gives a lot of features like multiupload, so I want to use this excellent http://blueimp.github.io/jQuery-File-Upload/ plugin for that. The problem is how to handle the file upload "in memory" like other form's data?
For example when we show the page for create new article we should be able to fill in article's data fields and select images to upload, next when we click the save button the images should start upload and after that the form should submit. When validation fails the images should be still displayed on the frontend, but on the server-side nothink should be saved.
One of the solutions is create somethink like "create entity session temporary id" before displaying the entire form and that id can be used to create temporary directory for save uploads, so after success saved form these images can be moved to appropriate directory, but how to make the "create entity session temporary id"?
The other solution I think is the "with the edit id" approach, because we can handle the uploads with previously saved gallery id, but sometimes I can't save new blank article with gallery, cause some of the fields should't be empty in db.
For the Rails I saw https://github.com/thoughtbot/paperclip gem which in the Readme says:
Paperclip is intended as an easy file attachment library for Active Record. The intent behind it was to keep setup as easy as possible and to treat files as much like other attributes as possible. This means they aren't saved to their final locations on disk, nor are they deleted if set to nil, until ActiveRecord::Base#save is called.
My question is how it works?
The problem with enabling file uploads on the create mask is that you eventually end up with orphaned files. This is because a user is able to trigger the upload without saving the actual entity. While creating a very own UploadBundle I thought about this problem for a while and came to the conclusion that there is no truly proper solution.
I ended up implementing it like this:
Given the fact that our problem arise from orphaned files, I created an Orphanage which is in charge of managing these files. Uploaded files will first be stored in a separate directory, along with the session_id. This helps distinguishing files across different users. After submitting the form to create the actual entity, you can retrieve the files from the orphanage by using only your session id. If the form was valid you can move the files from the temporary orphanage directory to the final destination of your files.
This method has some pitfalls:
The orphanage directory itself should be cleaned on a regular basis using a cron job or the like.
If a user will upload files and choose not to submit the form, but instead start over with a new form, the newly uploaded files are going to be moved in the same directory. Therefore you will get both the files uploaded the first time and the second time after getting the uploaded files.
This is not the ultimate solution to this problem but more of a workaround. It is in my opinion however cleaner than using temporary entities or session based storage systems.
The mentioned bundle is available on Github and supports both Orphanage and the jQuery File Uploader plugin.
1up-lab/OneupUploaderBundle
I haven't work with the case personaly, but my co-worker had similar conundrum. She used
punkave/symfony2-file-uploader-bundle
It's a bundle that wrapps jQuery File Upload plugin. It is in the early stages and a lot of things are missing, such as event, but we gave it a shot.
That's what we do: in newAction() we create entity, generate unique dir ID, and store the ID in entity (via regular setDirId()). Than we create the form, which contains hidden field dirId.
We are uploading the files to temp dir on server via ajax, not during the submit. Ajax request requires the ID. It stores files in temp_dir/prefix_ID
Than it's quite simple. Form is sent. If form is valid - move files from temp to dest dir. If not - we have the ID, and are able to show the images.
However, we do not save information about individual files in a separate table in the database. Every time we read the contents of the folder that corresponds to our dirId.
I know it's not the solution You are asking for. It's rather a workaround.
I know that its easy to upload single image with symfony and doctrine2.
But i want to have system like Google docs where i can see the progress bar of current image upload using doctrine2.
I know want to use thirdparty plugin.
Because i need to create an entity for everyimage and store it database with some detail. So i can just bulk upload with third party software in directory
is it possible or not
You may try AX Ajax Multi Uploader
Here is their homepage http://www.albanx.com/ (not relevant though)
You can use javascript to upload the file at client side .
Refer http://fineuploader.com/demos.html.
you can browse your files and trigger upload automatically or if you want to process the data at client side (say for a preview) you can process and trigger the upload manually as well.
you can also refer http://www.queness.com/post/11434/7-javascript-ajax-file-upload-plugins
and choose the lib which fits your requirement.
How does résumé upload work? I have a site in PHP and right now users can build their résumé line by line, because it is stored in db table. How can a user upload a resume in Word or other common format and have it uploaded into my db? Is it something to do with regex? Are there any scripts out there available that can do that?
Just trying to understand the process.
Thanks.
UPDATE:
BTW I looked around a bit and saw web-forms for resume creation -- I already have that. I need a user to be able to point webform to his/er resume, click SUBMIT and have that document input into db automagically.
Simply use the file uploading feature:
create a HTML page containing a <form> and a file input.
create a PHP script that receives the uploaded file
The process is simple: user selects a file to upload and the browser sends it to a PHP script designated by the action attribute of the <form> tag. After the file is uploaded into the server, you can do whatever you want with it.
PHP file upload tutorial
File uploading guidelines in PHP manual
I have a form where the admins will be uploading more then 2 pictures at a time, i had been using the basic HTML file input style, however i want to do more with it as i am using a beautiful admin theme from themeforest, (the author haven't included the styled file input element in skin), i want to do it manually. which should meet the following requirement
a) A styled file input element should
be displayed first
b) When the user gives the file input
it should automatically upload the
file using php
c)while uploading the file i want to
see the file upload progress with tool
tip
d)once all the files are uploaded the
user should be able to process the
form with already uploaded file.
I want to admit that i have a very basic understanding of how javascript and Jquery works, however i am quite good at PHP, HTML and CSS.
I want some kinda tutorial regarding how do i style my file input to fill my need.
i am searching something like this.. File Upload
thank you
The only thing that fulfills all your requirements in a way that works with most browsers at the moment is a Flash-based uploader like SWFUpload or Uploadify.
Use SWFUpload. Look its FEATURES DEMO. It has almost everything.