CUploadedFile create manyally - php

I want to offer 2 ways of uploading files - with <input type='file'> and remote upload by URL.
Is it possible to create a CUploadedFile using data from a remote url?

The remote upload is actually not an upload, rather the user submits the link and you need to copy it over to your server.
Consider CUploadedFile to be used only for the upload part and handover to the next file handler.
Once done with upload or copy, You might want to use another file management utility like cfile extension here http://www.yiiframework.com/extension/cfile/ to manage both your files already "copied/uploaded" to your desired directory.

Related

File upload using FileSystem in laravel5.1?

I want to upload file in laravel, I am using only local server and but not any cloud storage.
From doc,I found two methods related with file upload,
Normal method (Request::file('file')->move(dest,filename))
Using File system
But I could not understand actual difference between these methods?
If I am using normal method,
$file->move('path', $fileName);
Here where should be path located,storage/app or public/uploads(new)?
How can I upload files using File System ?
The "normal" method allows you to save the uploaded file only in the local filesystem in any place you choose, as long as PHP has write access to that location. This method can only be used for "save" operation and only for uploaded files.
The "filesystem" method is more flexible as it adds a layer of abstraction over the place you write to. Filesystem configuration is stored in a separate config and is transparent to your code. You can easily change the underlying storage (e.g. from local to cloud) or change paths without any changes to the code. The filesystem also gives you a lot of additional helper methods to operate on files it store, like list all files, checking existence, removing. Additional advantage is that it can be used to any files, not only the ones uploaded by the user during current request.
Answering your second question: you decide where to store files in both normal and filesystem method. In the normal method you pass the path, in filesystem you configure the paths using filesystems.php config.
And how to upload the file using File systems? You don't use the filesystem to upload the file, you use it to save the uploaded file. The upload process is the same, but instead of calling $uploadedFile->move() you do:
Storage::put('file key', file_get_contents(Request::file('file')->getRealPath()));
the difference between these two methods is about usage.
You use the "File System" service to work on your local/cloud file system, like creating, moving or deleting file. You could use the Storage::put() method to store the uploaded file, of course, but you would have to get the file from the request either way. So you normally just use the $request->file('photo')->move($destinationPath); method as specified in http://laravel.com/docs/5.1/requests#files to move the file where you want it to be. The File system service is not meant to handle uploads itself. That is what the Request is for.
The question about where you put the files is one you have to answer yourself. The default path for storing files is storage/app. You can put them to public/uploads but it is discouraged as anyone knowing the URL can download the files. It really depends on what the file is meant to. If it is a say profile picture then it can be put in public/uploads. Is the file private then is should not be put there but instead in storage/app.

Save txt file in specific location

I have a recursive function which generates about 200.txt files. I am running this application on a local server.
Basically, the front end just has a file upload field, which you just choose a .csv, which it then generates all the .txt files from that, but rather than saving them on the wamp server, is it possible to save them in a specific location?
Example, if I put another field in my front end called 'fileLocation', and the user types in the pathname.
Obviously i'd have to check if it's a directory etc, but is this possible to say save all the files on:
/Volumes/computer/Users/username/Desktop/test/
I'm not sure where to proceed with this.
No, is not possible to access computer files this way by using a localhost. You could zip all files and make the browser download them. Like is described here

Basic steps for setting up file upload on website

I'm trying to set up a file upload for my website but I'm not sure what I'd need to get this to work overall. I'm trying to use Jquery File Upload but I can't seem to get the files to upload to my server. It looks like I might need something else to get it to run but I'm not sure what. Any suggestions?
There are three "sides" to a file upload.
First is client-side: You need to have a form that can upload files (so you need to set the enctype attribute of your form element, and set your action to post).
Second is server-side: You need something that can handle the file upload. Assuming you're using a server with PHP, you can access the file via $_FILES['filename']. Google has a vast array of example for handling file uploads.
Third is server-side (again) - your server must allow file uploads. Not only must it allow file uploads, but it restricts the size of the file that can be uploaded (php config).
However, it looks like jquery file upload has a PHP file handler.
I will sugest you use dreamweaver its easy to use expecially to upload files to the web n you can also see the steps needed in its help content. or you may download an ftp uploader

is it posible to upload multiple files using a text file that contains the path to all files to be uploaded?

Is there any way to upload multiple files using a single file?...basically i want to upload multiple pdf files at once, using one single file that contains the path to each one of the pdf files...and store the information to mysql database...
PS: i dont want to merge all the files into 1 huge pdf...i want each 1 of pdf file to be uploaded to server dir at once and then store the file info to database eg. path, file info, filename for later use..
In order for a file to be uploaded, the user has to select that file manually. It's a security measure (otherwise websites could examine arbitrary files on your computer without your knowledge, which would be bad).
No - Because it would break the Javascript sandbox model (i.e. would be a security problem).
For security concern, it's hard to do this by javascript, which means you will have the access to others local files.
Why not just pack them up into a zip file then unzip on the sever side?

Uploading images from server using Php

In my php application i have a folder in which all the photos are kept.
The images are in different sizes.So i want to select photos from the folder and applying some image functions and upload to a different folder through php code.
This is same as image uploading but the difference is that the source file is in server
That is i want to select photos from server applying some image functions and upload again on the server
Pls help me
If you want to keep them on the same server, no further uploading is necessary. You can just perform whatever manipulations you want (resize, etc.) then use PHP's filesystem libraries to move the files around on the server. Check them out here.
maybe with curl http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html here a tip explaining how to send data with curl
If you select a photo from the folder and applied some image functions, instead of saving the file back to the original file, you could simply save it to it's new location...
In that case you don't need uploading and/or moving...

Categories