I am sorry if this has been answered before but all my searching is not coming up with a result.
I would like to place files directly into the target path and it not generate the UUID folder and then place the file in there. I know about the whole same filename could exist that is why I change the filename on the onChange event before uploading
I have tried to modify the handler.php but either I am not editing the correct lines or something else is going on.
After long and tiring, trying to figure this out, hours I have found a work around on this.
If you sent a blank uuid to the script it will not create the folder and will just place the file in the folder that you told the endpoint to put items. Not sure if this is how the script is supposed to work but it works for me.
I do not have to worry about files that are named the same as i have the script also change the file name before it gets upload with pre-prending a unique string to the file name.
callbacks:
{
onSubmit: function(id, name) {
this.setUuid(id, "")
console.log("onSubmit called")
}
}
Related
I have a function in my platform for letting users upload their own icon images. Once they've uploaded them I save them using $request->icon->store('public/icons') and simply save the returned path, something like "public/icons/xa6y2am3e4cOdqQuLpvEhFSXDKwFMDOgggS2i67l.png".
I'm not really clear though on what's the correct way to show the icons. The URL for showing the icon in the above example is "/storage/icons/xa6y2am3e4cOdqQuLpvEhFSXDKwFMDOgggS2i67l.png", thus I need to replace "public" in the path with "storage", which makes me think I've done something wrong somewhere (I see no reason why the store() method should provide me with a path that's not correct).
I have done my symlinks as described in the documentation. Using the local storage. What am I missing?
This is how I handle my storage in one of my apps that includes blogs:
$storedImageName = $request->file('main_image')->store('blog_images', 'public');
The store method actually returns the stored file name along with the path. Here, I specify that my disk is public and that the folder inside public is blog_images. I store the result of that in $storedImageName.
Now, to save it in the database, I do not actually save the whole path, I save ONLY the image name. This is because, you may want to update your directory name in the future, or move it to another location, etc. You can get that like this:
$onlyImageName = basename($storedImageName);
basename() is PHP's function, has nothing to do with Laravel.
This way, I can render my images in my blade files like this:
<img ... src="{{ asset('/storage/blog_images/' . $blog->main_image) }}" />
asset() helper will provide you with path to your public directory, and then you just need to specify the rest of the path to your image.
I have a Laravel website and I have several routes that load the contents of images from Storage. I do this using the following code:
public function show_image($name) {
echo Storage::disk('images')->get($name);
}
I want to prevent users being able to set name to something like ../../../error.log. So I don't want users to escape the Storage directory. I have a few ideas on how to accomplish this however I want to know is there a best practice?
If you need just file name, not location, disallow them from inputting folder of any kind. Just cut the string on /.
end(preg_split("#/#", $name));
When you need to allow some folders and all of the contents, check the folder name, subfolder name, etc.
You could either keep a registry/index of the uploaded images, and only allow the user to show a image from that registry (e.g. an images database table).
Or you could do a scan of the directory, that you are allowing files from, and make sure, that the requested file is in that list.
public function show_image($name) {
$files = Storage::disk('images')->files();
if (! in_array($name, $files)) {
throw new \Exception('Requested file not found');
}
echo Storage::disk('images')->get($name);
}
(code untested)
In macOS, I want a folder action to trigger when I place a new file in that folder. The action should grab the filename, not including the path, and use that as the subject, and then attach the file to an email message and send it. Ideally, this would happen behind the scenes as I don't need to see the activity.
I created an Automator script that can grab the file, extract the name, create and send the file. But it's a bit of a kludge. Once I set a variable to the filename, I lose the attachment and have to get the finder item again. Also, it's not working as a Folder Action which is what I really need.
The Automator includes these steps:
Get Specified Finder Items
Get Folder Contents
Filter Finder Items -- I'm only interested in specific files
Set Value of Variable
--path
Run Shell Script -- extract only the filename without the extension
--basename "$#" .pdf
Set Value of Variable
--fileName
New Mail Message
--Subject: fileName
At this point I no longer can attach the specified file because Automator has 'lost' it, so I have to start over with the Get Specified Finder Items, Get Folder Contents, Filter Finder Items, Add Attachments to Front Message. Finally, Send Outgoing Messages.
What I want to happen is when I place a certain file into a directory, the Folder Action triggers, it looks at the file, and if it meets the filter criteria it emails the file, using only the filename without the extension as the Subject.
Create an Automator document type that is a folder action, and attach it to the desired folder. Items added to the specified folder will be passed on to the workflow, so you don’t need to use additional actions to get them.
You are already saving the filtered item paths in a variable, you just need to get them back for the Mail action:
Folder Action receives files added to { wherever }
Filter Finder Items
Set Value of Variable { Variable: path }
Run Shell Script
Set Value of Variable { Variable: fileName }
Get Value of Variable { Variable: path } (ignore input)
New Mail Message { Subject: fileName } (passed files are attached)
Automator workflows are designed to work with multiple input items as a batch; dealing with items one at a time would require a script or third party action such as Dispense Items Incrementally.
I am developing project. Which is related to honey pots.My problem is there any way to get open source honey pot log files.If it possible, Please provide a link or give any suggestions
That would be very easy to do. Here's a PHP example:
if($_POST[shouldBeEmpty] == "") {
// the field is empty, so deal with the form submission
}
else {
// you are dealing with a spammer, therefore add to the log file
}
Of course, don't name your field "shouldBeEmpty". Name it something normal-sounding such as "contactNumber" or "message".
Here is my BrandController.php
https://gist.github.com/a958926883b9e7cc68f7#file-brandcontroller-php-L53
I've gone through all my files of my custom module, and compared them to the one given from the custom module maker, and I couldn't find much differences.
Are you attempting to upload multiple files? If you're using multiple fileupload elements with the same name you'll get an array of items.
So when the following line is called,
//this way the name is saved in DB
$data['filename'] = $_FILES['filename']['name'];
It will have the value
["name"]=>array(2) {
[0]=>string(9)"file0.txt"
[1]=>string(9)"file1.txt"
}
you'll need to update the code to loop through each $_FILES['filename']['name'] and upload and save the files separately.
You may unknowingly uploaded multiple files. If you that is not your intention, you may check your in your HTML and check the name attribute of the tag. It must not be an array (like this).
<input type="file" name="my_files[]" />
If you only see Array() in your database, it means you are indeed uploading a multiple files. You can process them by using loops.
If you are really sure that you are uploading 1 image, you may follow #Palanikumar's suggestion. Use a print_r() and display the $_FILES and paste it here. IF you don't want to use that, You can use
json_encode($the-data-you-are-going-to-insert-to-the-database);
If you don't know where to put the print_r() function, you may put it after line 56 of this file.
https://gist.github.com/desbest/a958926883b9e7cc68f7#file-brandcontroller-php-L53
if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
print_r($_FILES);
die;
If saveAction() is being called inside an ajax function you need to log the ajax response. Assuming you are using jquery..
$ajaxResponse = $.POST({...});
console.log($ajaxResponse.responseText);
Then, you you can view it inside a browser's console. If nothing appears, you may use a non-async request
$ajaxResponse = $.POST({
// your options,
// your another option,
async: FALSE
});
Usually file upload will return in array format. So that each uploaded file will have the information like name, type, size, temporary name, error. You can get the file information using print function (print_r($_FILES)). So if you want to display name of the file you have to use something like this $_FILES['filename']['name']
Use print function and debugging tool then save file information using loops.
For more info please check here.
You aren't setting the enctype of the form so the image will never be sent. updated the code to
$form = new Varien_Data_Form(array( 'enctype' => 'multipart/form-data'));