Upload image form and other fill form

I have a form with data such as name, address ... and another separate upload profile profile form. And I want to get this (optional) uploaded image when submitting a "parent" (separate) form.
Now they work as follows:
The uploaded pic is sent via .ajaxSubmit() to process_uploaded_image.php. Then it is processed, changed, and a new image is created in the "dump / tempo" folder. I could return it to success: function(data) , in the form of data, which could be an echo of $image_path_and_name or as <img src="$image_path_and_name"/> . I did it like this: I have a temporary image, since
(1) I want the user to look at what he just loaded (remember that I already have a return path or img element for jquery and I could place it wherever I want) and
(2) the uploaded image is not final until the parent form completes the registration. And yet this is a temporary image.

So the problem is that: I want to access the downloaded image and โ€œbring itโ€ with the โ€œparentโ€ form when it is sent ... how can I do this for sure? This is technically not a parent form, as I know that a form inside a form is not allowed. But he is tied logically under this parental form. I would be grateful for any help, but if possible, I would appreciate it even more if you could consider my current scenario, so I no longer have to start from scratch. Thanks again. My idea: (please let me know as much as possible ... and / or a guide on how I could do # 1)
1. "Restore" or copy this file from ajax-jquery, returned (data) line $image_path_and_name or <img src="$image_path_and_name"/> , put it in the final folder for downloading. <--- THIS WHERE I AM STOPPED! I could not just use move_uploaded_file() , can I?
2. Since everything is final from now on ... I can save its path to my database, as well as other form information.
3. Launch the dump / tempo folder.

+4
source share
3 answers

My solution is that using iframe to load and use javascript like this on iframe return page

 echo("<script type=\"text/javascript\">parent.insert('". $WHAT_YOU_WANT . "');</script>"); 

and the insert function is defined on the parent page and can insert the row where you want. obj_ta is the target text field or something else.

 //A simple input function insert(str) { obj_ta.value = str; } //A textfield which accept some other user inputs function insert(str) { var startPos = obj_ta.selectionStart, val = obj_ta.value; obj_ta.value = val.substring(0, startPos) + str + val.substring(startPos, obj_ta.value.length); } 
+2
source

Make the two folders one temporary and the other final ....... and after loading the image, put the file name in a hidden field in the main form ........ then, when sending data to the database, it moves the image to the destination folder and name (from a hidden field) to the database.

+1
source

If you have a file location, and after the user checks and confirms the image, you can use the copy function to copy from your temporary folder to the main folder .so it will be like

 1) copy($file, $newfile) 

2) Update the database of the new path.

3) Detach the file from the old path.

 unlink($file); 

Read more about Unlink File

+1
source

Source: https://habr.com/ru/post/1444259/


All Articles