AnomaIy Posted December 3, 2012 Share Posted December 3, 2012 <script language="javascript" type="text/javascript"> <!-- function startUpload(){ document.getElementById('myf1_upload_process').style.visibility = 'visible'; document.getElementById('myf1_upload_form').style.visibility = 'hidden'; return true; } function stopUpload(success){ var result = ''; if (success == 1){ result = '<span class="mymsg">The file was uploaded successfully!<\/span>'; } else { result = '<span class="myemsg">There was an error during file upload!<\/span>'; } document.getElementById('myf1_upload_process').style.visibility = 'hidden'; document.getElementById('myf1_upload_form').innerHTML = result + '<br/>File: <input name="myfile" type="file" accept="image/*" size="0" /><input type="submit" name="submitBtn" class="mysbtn" value="Upload" />'; document.getElementById('myf1_upload_form').style.visibility = 'visible'; editor = ipb.textEditor.getEditor(ipb.topic.fastReplyId); editor.insert("[img= URL For Upluaded Photo After Upload ]", true ); return true; } //--> </script> <?php // Edit upload location here $destination_path = getcwd().DIRECTORY_SEPARATOR; $result = 0; $target_path = $destination_path . basename( $_FILES['myfile']['name']); $imagetypes = array( 'image/png' => '.png', 'image/gif' => '.gif', 'image/jpeg' => '.jpg', 'image/bmp' => '.bmp'); $ext = $imagetypes[$_FILES['myfile']['type']]; $randval = time(); $newname = $randval . $ext; if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $newname)) { $result = 1; } sleep(1); ?> <script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result; ?>);</script> editor.insert("[img= URL For Upluaded Photo After Upload ]", true ); How to receive link after upload instead "URL For Upluaded Photo After Upload" Quote Link to comment https://forums.phpfreaks.com/topic/271525-how-to-receive-link-after-upload/ Share on other sites More sharing options...
Christian F. Posted December 3, 2012 Share Posted December 3, 2012 Echo out the $newname for the image (from the PHP script), receive it in the JS, and add it to the string. Quote Link to comment https://forums.phpfreaks.com/topic/271525-how-to-receive-link-after-upload/#findComment-1397116 Share on other sites More sharing options...
AnomaIy Posted December 3, 2012 Author Share Posted December 3, 2012 (edited) @Christian F., Thank you for your attention Tried but failed ... please write your version of how to implement, if you have free time: editor.insert("[img= URL For Upluaded Photo After Upload ]", true ); ??? Edited December 3, 2012 by AnomaIy Quote Link to comment https://forums.phpfreaks.com/topic/271525-how-to-receive-link-after-upload/#findComment-1397118 Share on other sites More sharing options...
Christian F. Posted December 3, 2012 Share Posted December 3, 2012 I'm afraid I won't be doing that, as I'm not here to write the code for others. At least not without getting paid for it. However, if you post what you tried to do, and explained how it "failed", then I'm sure I (or someone else) can help you figure out what you did wrong. That's what I'm here for: To help others learn. Quote Link to comment https://forums.phpfreaks.com/topic/271525-how-to-receive-link-after-upload/#findComment-1397137 Share on other sites More sharing options...
AnomaIy Posted December 3, 2012 Author Share Posted December 3, 2012 (edited) 1. editor.insert("[img=+$newname+]", true ); 2. editor.insert("[img=+'<img src=<?php echo $newname; ?> />'+]", true ); 2. editor.insert("[img=+'<?php echo $newname; ?>'+]", true ); Edited December 3, 2012 by AnomaIy Quote Link to comment https://forums.phpfreaks.com/topic/271525-how-to-receive-link-after-upload/#findComment-1397141 Share on other sites More sharing options...
Christian F. Posted December 3, 2012 Share Posted December 3, 2012 The problem you're having is that the file you're editing is not being re-parsed by the server when uploading the file, which is why you're using AJAX. So you'll need to edit the actual file that does the uploading, the code in the last box, to echo out the name and location of the image. That will be sent to the calling AJAX code, in which where you can retrieve it from the result. I recommend reading up a bit more up on how AJAX works, and possibly using jQuery if you're not already. Bit difficult to say exactly what you should do, as there seems to be some code missing in the blocks you've posted. Quote Link to comment https://forums.phpfreaks.com/topic/271525-how-to-receive-link-after-upload/#findComment-1397147 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.