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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.