Download jQuery and PHP / MySQL - change the file name at startup

I use Uploadify as part of the form. Let me give you some background, this may help. I have a form where the user can add “projects” to the website. First they enter the project name and description. In the view, this updates the PHP / MySQL database table named "project" and gets the identifier.

The user can then upload files to a location on the server. I want to add the project name at the beginning of the file name for the download AND the project ID (which I need to add to the database) before the download starts, and then when the download is complete, add the file data to the database table "image" - associated with " project "through the project identifier.

I know that I bounced back and forth a bit, I need to know how to do this. Two database tables for updating, one for submit and one for uploading files. I need to pass the project name and ID to upload the upload script.

DECISION:

I had to use the uploadify method below to send the project ID to the uploadid script, pre-populating the variable with the pidresult mysql_insert_id:

'onSelectOnce': function(event,data) {
     $('#file_upload').uploadifySettings('scriptData', {'pid': pid});
 }

Then I could get the pid variable in the PHP uploadify script using a simple entry:

$pid = $_POST['pid'];

Then it was necessary to make a choice inside this script to get the data I needed for the database (the project alias) and add it to the file name before downloading:

    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/' . $alias . '-';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

Hope this helps people in the future.

+3
source share
3 answers

uploadify uploadid script, pid mysql_insert_id:

'onSelectOnce': function(event,data) {
     $('#file_upload').uploadifySettings('scriptData', {'pid': pid});
 }

pid PHP uploadify script, :

$pid = $_POST['pid'];

select script, ( ) :

$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/' . $alias . '-';
$targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

, .

+3

uploadify script , , . script , hs .

ajax, , 2 , user_id ID , , , ur.

   var = file_before_upload_name: filename // here use the sytax that Uploadify uses to capture the name of the file
   var = file_after_upload_name: filename // here use the sytax that Uploadify uses to capture the name of the file

ajax

uid: uid// before: file_before_upload_name, : file_after_upload_name

ajax

mysql_queries("INSERT INTO `tbl-projects` SET `user_id` = {$_POST['uid']}, `file` = {$_POST['after']}");

//another query here to set the data to your other table that relates to tbl-projects
+1

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


All Articles