wwfc_barmy_army Posted November 28, 2009 Share Posted November 28, 2009 Hello. I have a Jquery image upload script which I found on the internet and i've already made a number of changes to it, although I'm not the best at ajax stuff yet, but I don't know how I can get it to return the random file name created in the php upload script. The image is uploaded with the random file name, but just not returned to the main page yet. Here is my code: In my main page: <script language="javascript" type="text/javascript"> $(document).ready(function(){ $('#status').hide(); }); $(function(){ var ipup = 0; var btnUpload=$('#upload'); var status=$('#status'); new AjaxUpload(btnUpload, { action: 'upload-file.php', //Name of the file input box name: 'uploadfile', onSubmit: function(file, ext){ if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ // check for valid file extension status.text('Only JPG, PNG or GIF files are allowed'); return false; } status.text('<img src="images/ajax-loader.gif"> Uploading...'); $('#status').show(); }, onComplete: function(file, response){ //On completion clear the status status.text(''); $('#status').hide(); //Add uploaded file to list if(response==="success"){ $('<li></li>').appendTo('#files').html('<img src="./images/upload/'+file+'" alt="" /><br />'+file).addClass('success'); $('<p></p>').appendTo('#files').html('<input name="file' + ipup + '" type="hidden" value="' +file+ '" /><br />'); ipup = ipup + 1; } else{ $('<li></li>').appendTo('#files').text(file).addClass('error'); } } }); }); </script> Upload-file.php <?php $uploaddir = './images/upload/'; // get the file extension first $ext = substr(strrchr(basename($_FILES['uploadfile']['name']), "."), 1); // make the random file name $randName = md5(rand() * time()); // and now we have the unique file name for the upload file $file = $uploaddir . $randName . '.' . $ext; //$result = move_uploaded_file($tmpName, $filePath); //$file = $uploaddir . basename($_FILES['uploadfile']['name']); if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { echo "success"; } else { echo "error"; } ?> As far as I can see if I echo it the returning value will not be success so will not work, so I'm not sure the best way to go about it. Thanks for any help and advice. Link to comment https://forums.phpfreaks.com/topic/183202-upload-image-changes/ Share on other sites More sharing options...
wwfc_barmy_army Posted December 2, 2009 Author Share Posted December 2, 2009 nobody? Link to comment https://forums.phpfreaks.com/topic/183202-upload-image-changes/#findComment-970095 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.