Jump to content

Recommended Posts

Hello All,

 

I have a script that lets people go back and edit an upload to my site. The path of the file isn't getting dumped into the database. There are three php files that do the work. It works fine for the original upload, but the variable ($id primary id that points to the record in the database) gets lost in the version where they do the edit. I've manually entered the variable and it puts the path to the file into the database. I'm including the script for all three pages. The variable isn't getting passed properly to the third script. If anyone can point me in the right direction, I'd appreciate it!

 

Code for Form:

<form action="edit_videoscript.php " method="post" enctype="multipart/form-data" name="uploadform">
<font class="forms">First Name:<br>
<input type="text" value="<?=$row['first_name']?>" name="first_name" id="first_name" class="story"/>
<br><br>
E-Mail:<br>
<input value="<?=$row['email']?>" type="text" name="email" id="email" class="story"/>
<br><br>
<a href="javascript:openCityStatePhotoWindow();" class="linkpopup">City & State:<br></a>
<input value="<?=$row['city']?>" type="text" name="city" id="city" class="storycity"/>
<? include 'library/state1edit.php'; ?>
<br><br>
<a href="javascript:openLinksWindow();" class="linkpopup">Web Link:<br></a>
<input value="<?=$row['link']?>" type="text" name="link" id="link"  class="story"/>
<br><br>
<a href="javascript:openVideoWindow();" class="linkpopup">Video:<br></a>
<input name="userfile" type="file" id="userfile" class="storyphoto">
<br><br>
<a href="javascript:openCaptionVideoWindow();" class="linkpopup">Video Caption:<br></a>
</font>
<textarea name="caption" id="caption" wrap="hard" class="storycaption"><?=$row['caption']?></textarea><br>
<br><br>
<input type="hidden" name="thanks" value="7">
<input type="hidden" name="id" value="<?=$row['id']?>">
<input name="upload" type="submit" id="upload" value="Upload" class="storybtn" onClick="YAHOO.example.container.wait.show();">
</form>

 

Code for the script that starts the upload and puts all but the path into the database

<?php
$host = 'localhost';
$user = 'xxxxxx';
$pass = 'xxxxxx';
$db = 'xxxxxx';
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());

// Set variables
$hasPortrait = false;
if ($_FILES['userfile']['name'] != "") {
        $hasPortrait = true;
    }

if (!$hasPortrait) {	

// Set variables
$id=$_POST['id'];
$first_name = $_POST['first_name'];
$email = $_POST['email'];
$city = $_POST['city'];
$state = $_POST['state'];
$link = $_POST['link'];
$caption = $_POST['caption'];
$thanks = $_POST['thanks'];

// Insert into database
$query = "UPDATE uploads_content SET
         first_name = '$first_name', 
         email = '$email', 
	 city = '$city', 
	 state = '$state',
	 link = '$link',
	 caption = '$caption',
	 approved = '0'
	 WHERE id = '$id' ";
mysql_query($query) or die('Error, query failed : ' . mysql_error()); 
if($query)
{header( "Location: http://www.pavementmemories.com/thanks.php?first_name=$first_name&thanks=$thanks" );}
else
{header( "Location: http://www.pavementmemories.com/oops_contact.php" );}
}		 

else {

$temp_video = '/home/grozanc/public_html/pavementmemories.com/videos/temp/';
$video_processor = '/home/grozanc/public_html/pavementmemories.com/process_video2.php';

if(isset($_POST['upload']))
{
    $first_name = $_POST['first_name'];
$email = $_POST['email'];
$city = $_POST['city'];
$state = $_POST['state'];
$link = $_POST['link'];
$caption = $_POST['caption'];
$thanks =$_POST['thanks'];
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

    // get the file extension first
$ext = substr(strrchr($fileName, "."), 1); 

// generate the random file name
$randName = md5(rand() * time());

    if(!get_magic_quotes_gpc())
    {
        $fileName  = addslashes($fileName);
        $filePath  = addslashes($filePath);
}

if( is_uploaded_file($_FILES['userfile']['tmp_name']) )
{
	$newfile = $randName . '.' . $ext;
	move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_video . $newfile);	
}

   								
$cmd = '/usr/bin/php ' . $video_processor . ' "' .  $temp_video . $newfile .'" ' . $randName . ' ' . $insert_id;
proc_close( proc_open( $cmd . " >> /home/grozanc/public_html/logs/videoprocess.log &", array(), $foo ) );

//exec('/usr/bin/php ' . $video_processor . ' "' .  $temp_video . $newfile .'" ' . $randName . ' ' . $insert_id .' &', $out,$rval);

file_put_contents('/home/grozanc/public_html/logs/videocommands.log',"\n" . $cmd,FILE_APPEND);

//header("Location: http://www.pavementmemories.com/thanks.php");
//exit;

$first_name = str_replace("'","’",$first_name);
$city = str_replace("'","’",$city);
$caption = str_replace("'","’",$caption);

$query = "UPDATE uploads_content SET 
                     first_name = '$first_name', 
					 email = '$email', 
					 city = '$city', 
					 state = '$state', 
					 link = '$link', 
					 caption = '$caption', 
					 name = '$fileName',
					 approved = 0, 
					 featured = 0
					 WHERE `id` = '{$id}' ";

mysql_query($query) or die('Error, query failed : ' . mysql_error()); 

$insert_id = mysql_insert_id();


include ( "thanks.php" );
exit;	
  }
}  

?>

 

This last script gets called from the previous one to process the upload and isn't getting the $id variable in the query. If I enter an id of an existing record instead of the $id, it runs the update.

<?php
require_once('xxxxxx');
$id=$_GET['id'];
$base_dir = '/home/grozanc/public_html/';
$web_dir = $base_dir . 'pavementmemories.com/';
$log_dir = $base_dir . 'logs/';
$videos_dir = 'videos/';

$sample_rates = array(44100, 22050, 1102);

$ffmpeg_binary = "/usr/bin/ffmpeg";
$flvtool2 = "/usr/bin/flvtool2";

$width = '320';
$height = '240';

$srcfile = $argv[1];
$destfile = $videos_dir . $argv[2] . '.flv';

$fulldest = $web_dir .  $destfile;

$ffmpegObj = new ffmpeg_movie($srcfile);
$srcFPS = $ffmpegObj->getFrameRate();
$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
$srcAR = $ffmpegObj->getAudioSampleRate();

if( !in_array($srcAR,$sample_rates) )
$srcAR = 44100;

//exec($ffmpeg_binary . ' -i ' . $srcfile . ' ' . $destfile . " | " . $flvtool2 . " -U stdin " . $destfile,$output,$retval);
$vid_command = $ffmpeg_binary . " -i " . $srcfile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $width . "x" . $height . " " . $fulldest;
file_put_contents($log_dir . 'ffmpegcmd.log', "\n" . $vid_command, FILE_APPEND);
exec($vid_command,$output,$retval);

/*
echo "Ret Val: $retval<br>";
echo "<pre>";
print_r($output);
echo "</pre>";
*/

$logdata = date("m-d-Y") . "\n" . var_export($output,true) . "\n\n";
file_put_contents($log_dir . 'videooutput.log', $logdata,FILE_APPEND);

$destfile = $_POST['path'];

mysql_query("
	UPDATE uploads_content
	SET video_processed = 1,
		path = '$destfile'
	WHERE `id` = '$id'
");
echo mysql_error();


?>

Link to comment
https://forums.phpfreaks.com/topic/95124-variable-wont-pass/
Share on other sites

I'm trying to include the last of the three pieces of code into the second. I also tried posting the id and that didn't work either. It's frustrating, that it works when you simply upload a new file but it doesn't when you edit and old upload unless I use the actual primary id instead of having the variable pass.

Link to comment
https://forums.phpfreaks.com/topic/95124-variable-wont-pass/#findComment-487435
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.