0

I am using the Uploadify Plugin to upload the picture, and i am doing some operations like

a) when a user upload the file the upload button is removed automatically b) and the uploadify.php script will rename the file and store it in designated directory.

and here is the code which i am using to perform the action.

Jquery Code :

<script type="text/javascript"> $(document).ready(function() { $('#fileUpload, #fileUpload2').uploadify({ 'uploader': 'img/uploadify.swf', 'script': 'uploadify.php', 'folder': 'upload', 'auto' : 'true', 'cancelImg': 'img/cancel.png', 'fileDesc': 'jpg/jpeg', 'displayData': 'percentage', 'fileExt': "*.jpg;*.jpeg", 'sizeLimit' : '8388608', 'fileDataName' : 'file', onComplete : function(event, queueID, fileObj, reposnse, data) { $('#filesUploaded').append('<a href='+fileObj.filePath+'>'+fileObj.name+'</a><br>'); $("#firstUpload").remove(); } }); }); </script> 

and in the php i have used the combination of date with a unique id to rename the file which is perfectly working fine.

but when i want to view the file name and i do that by calling the div

<div id="filesUploaded"></div> 

it shows the original filename and not the renamed file. i tried changing the value from '+fileObj.name+' to '+response+'

i guess the problem is within the above code as the file.Obj.name prints the selected file name and not the processed file, and when i change it to +response+ it uploads the file and rename it but in the form page it does not print the renamed file name. and it freezes with the progress bar composing 100% progress.

how do i make it print the renamed file name.?

thank you

Edit : here is my PHP code .

<?php include('database.php'); $date = date("dFY"); $query = "SELECT MAX(id) as max_id FROM news"; $result = mysql_query($query); $row = mysql_fetch_array($result); $max_id = $row['max_id']+1; echo $max_id; $file1 = "file_$date"."_$max_id.jpg"; if (!empty($_FILES)) { $tempFile = $_FILES['file']['tmp_name']; $targetPath = 'upload/'; move_uploaded_file($tempFile,$targetPath.$file1); } ?> 
2

2 Answers 2

4

For me this didn't work. I was looking for something similar - this is what worked for me:

'onUploadSuccess' : function(file, data, response) { alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data); } 

In my case I used my uploadify.php to create a unique filename - then I used echo $filename - rather than '1'. That way "data" always contains the newest filename. Cheers

Sign up to request clarification or add additional context in comments.

Comments

1

Here's the problem. The Javascript code has a typo. You have written reposnse instead of response in onComplete call. Do it like this:

 onComplete : function(event, queueID, fileObj, response, data) 

Then when you do the +response+, the script will not hang and will show the MaxID (which you're outputing from the PHP script).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.