Solution 1 :

Here is the code, I hope it works:

     <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<?php
// Simple PHP Upload Script:  http://coursesweb.net/php-mysql/

$uploadpath = 'upload/';      // directory to store the uploaded files
$max_size = 5000;          // maximum file size, in KiloBytes
$alwidth = 900;            // maximum allowed width, in pixels
$alheight = 800;           // maximum allowed height, in pixels
$allowtype = array('png', 'mp3');        // allowed extensions

if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
  $uploadpath = $uploadpath . basename( $_FILES['fileup']['name']);       // gets the file name
  $sepext = explode('.', strtolower($_FILES['fileup']['name']));
  $type = end($sepext);       // gets extension
  list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);     // gets image width and height
  $err = '';         // to store the errors

  // Checks if the file has allowed type, size, width and height (for images)
  if(!in_array($type, $allowtype)) $err .= 'The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.';
  if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
  if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;

  // If no errors, upload the image, else, output the errors
  if($err == '') {
    if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) { 
      echo 'File: <b>'. basename( $_FILES['fileup']['name']). '</b> successfully uploaded:';
      echo '<br/>File type: <b>'. $_FILES['fileup']['type'] .'</b>';
      echo '<br />Size: <b>'. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .'</b> KB';
      if(isset($width) && isset($height)) echo '<br/>Image Width x Height: '. $width. ' x '. $height;
      //echo '<br/><br/>File address: <b>http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'</b>';
        echo '<br><br><br> NOW COOPY THIS LINK';
      
    }
    else echo '<b>Unable to upload the file.</b>';
  }
  else echo $err;
}
?>
<div style="margin:1em auto; width:333px; text-align:center;">
 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data"> 

           
 <input type="text" value=<?php echo 'http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'';?> id="myInput">

<?php 
if(isset($err) && $err == '')
{
?>
 <button onclick="myFunction()">Copy text</button>
<?php 
}
?>
    
 <script>
function myFunction() {
 var copyText = document.getElementById("myInput");
  copyText.select();
    copyText.setSelectionRange(0, 99999)
     document.execCommand("copy");
    alert("Copied the text: " + copyText.value);
   }
  </script> 

<br><br>




 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data"> 
  Files uploader for DANMAKU CREATE<br>Allowed files: .png(max 1mb) .mp3(max 5 mb)<br><br> <input type="file" name="fileup" /><br/><br>
  <input type="submit" name='submit' value="Upload" /> 
 </form>
</div>

this is what I changed on your button. The error variable must be set(because that means it passed the post request) and must be empty to check if there was an error or not:

<?php 
if(isset($err) && $err == '')
{
?>
 <button onclick="myFunction()">Copy text</button>
<?php 
}
?>

Problem :

Ok so i found this file uploader, its something exactli i need to my game – a image and music uploader.

Well orginally there was just link you can copy and select so i made little textbox with copy button you can see at bottom but its visible even before file is uploaded. help me dooing this to appear only after file upload. I dont know much about website coding, i cant handle it without “if” 😀

 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<?php
// Simple PHP Upload Script:  http://coursesweb.net/php-mysql/

$uploadpath = 'upload/';      // directory to store the uploaded files
$max_size = 5000;          // maximum file size, in KiloBytes
$alwidth = 900;            // maximum allowed width, in pixels
$alheight = 800;           // maximum allowed height, in pixels
$allowtype = array('png', 'mp3');        // allowed extensions

if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
  $uploadpath = $uploadpath . basename( $_FILES['fileup']['name']);       // gets the file name
  $sepext = explode('.', strtolower($_FILES['fileup']['name']));
  $type = end($sepext);       // gets extension
  list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);     // gets image width and height
  $err = '';         // to store the errors

  // Checks if the file has allowed type, size, width and height (for images)
  if(!in_array($type, $allowtype)) $err .= 'The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.';
  if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
  if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;

  // If no errors, upload the image, else, output the errors
  if($err == '') {
    if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) { 
      echo 'File: <b>'. basename( $_FILES['fileup']['name']). '</b> successfully uploaded:';
      echo '<br/>File type: <b>'. $_FILES['fileup']['type'] .'</b>';
      echo '<br />Size: <b>'. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .'</b> KB';
      if(isset($width) && isset($height)) echo '<br/>Image Width x Height: '. $width. ' x '. $height;
      //echo '<br/><br/>File address: <b>http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'</b>';
        echo '<br><br><br> NOW COOPY THIS LINK';
      
    }
    else echo '<b>Unable to upload the file.</b>';
  }
  else echo $err;
}
?>
<div style="margin:1em auto; width:333px; text-align:center;">
 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data"> 

           
 <input type="text" value=<?php echo 'http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'';?> id="myInput">
 <button onclick="myFunction()">Copy text</button>
    
 <script>
function myFunction() {
 var copyText = document.getElementById("myInput");
  copyText.select();
    copyText.setSelectionRange(0, 99999)
     document.execCommand("copy");
    alert("Copied the text: " + copyText.value);
   }
  </script> 

<br><br>




 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data"> 
  Files uploader for DANMAKU CREATE<br>Allowed files: .png(max 1mb) .mp3(max 5 mb)<br><br> <input type="file" name="fileup" /><br/><br>
  <input type="submit" name='submit' value="Upload" /> 
 </form>
</div>

Comments

Comment posted by Martin

What you’re looking for is javascript / jQuery.

Comment posted by Martin

Please edit your answer and explain what you changed and why it works

Comment posted by Noxium

@Martin I’m sorry, I thought it would be useless to explain what I changed because the post creator just said he doesn’t know web developing

Comment posted by Ten GoliBroda

ok that was clever. i tried something similiar but inside single php tag and with echo. Could you help renaming file to number of files inside folder? because it seems this replaces file with same name.

Comment posted by Martin

@Noxium Stack Overflow is also for others with similar problems to find solutions too

By