Jump to content

How To Receive Link After Upload


AnomaIy

Recommended Posts

<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"

Link to comment
https://forums.phpfreaks.com/topic/271525-how-to-receive-link-after-upload/
Share on other sites

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. ;)

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.