Jump to content

Dynamically inserting value


bruckerrlb

Recommended Posts

Hello all,

 

I have a simple script, yet I just cannot figure out how to get one part working. What will happen is the user uploads a picture. Then the user will have the option to insert that picture with a button in the text area (it's a cms). Yet I am having problems with the second part. Here is my code for the button the user will be using

 

<input type="button" value="B" onClick="document.forms['submitnews']. elements['press'].value=document.forms['submitnews']. elements['press'].value+'<?php echo test; ?>'"> 

 

Where the echo test is, is where I want to put the address to the file, yet how it works is, first the user uploads a picture. Then it has all of the statements about that picture are echoed out for the user to see. How do I get that echo information into variables? Any help is much appreciated and if you need me to be more clear about something I will do that.

Link to comment
https://forums.phpfreaks.com/topic/80125-dynamically-inserting-value/
Share on other sites

I'll post my storage code here and comment to let you know what's going on

 


//if the submit button is pushed
if(isset($_POST['submitvideo']))  {



  
//defines what can be uploaded
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "application/x-shockwave-flash")
|| ($_FILES["file"]["type"] == "application/octet-stream")
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
//if the files are good files then it will echo all the info here
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    if (file_exists("uploads/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
       //move them to a perm. folder
      move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
  $filepath = $_FILES["file"]["name"];
      echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
          //this was my attempt at using css to put the file in the div where I wanted it to go, it (I) failed
  echo "<div class\"imgdynamic\"><img src=\"uploads/$filepath\" /></div>";
       //I am only storing flash video paths into a database
  if (($_FILES["file"]["type"] == "application/x-shockwave-flash"))
  {
  $query = "INSERT INTO videos
	(id, path)
	VALUES (0, '$thefile')";

	if (@mysql_query ($query)) {
	print 'Successfully Added!';
	}
   }
      }
    }
  }
else
  {
  echo "Invalid file";
  }
  
  }
mysql_close();

	?>

 

I hope that helps, thanks again!

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.