Jump to content

Recommended Posts

Hiya peeps!

 

I have built this code, can anyone see anything wrong with this because its not working at all all it does is refer back to its self;

 

<?php session_start();

include 'system/template/template.php';
include 'system/mysql/mysql.php';
include 'system/properties/property.php';

	$mysql = new mysql();
	$mysql->connect();

	$property = new property();

	if($property->landlord_loggedin()) {
		header('Location: login.php');
	}


	$_SESSION['N_P_ID'] = 1;
if(isset($_SESSION['N_P_ID']) && !empty($_SESSION['N_P_ID'])) {
	if(isset($_POST['videotitle']) && !empty($_POST['videotitle']) && isset($_FILES['videofile']) && !empty($_FILES['videofile'])) {
		$upload = $bad . '<form id="Upload" action="upload_video.php" enctype="multipart/form-data" method="post">
					<h3>Upload a video of your property</h3>
					<label>Video Title</label>
					<input type="text" name="videotitle"><br />
					<input type="file" name="videofile">

					<label>Submit</label>
					<input type="submit" name="submit" value="Upload"><br />
					<a href="landlord_account.php">Skip</a>
				</form>';

		$extensions = array('mpg', 'avi', 'mpeg');
		define ("MAX_SIZE","10240"); 

		function getExtension($str) {
			$i = strrpos($str,".");
			if (!$i) {
				return "";
			}

			$l = strlen($str) - $i;
			$ext = substr($str,$i+1,$l);

			return $ext;
		}

		if(isset($_FILES['imageone'])) {

			if(!isset($_POST['videotitle'])) {
				$bad = '<p class="bad">Please enter a video title.</p>';
				$form = $upload;
			}

			$filename = stripslashes($_FILES['videofile']['name']);

			$extension = strtolower(getExtension($filename));

			if(!in_array($extension, $extensions)) {

				$bad = '<p class="bad">Video is incorrect format, please make sure your video format is either mpg/mpeg or avi.</p>';
				$form = $upload;

			} else {

				$size = filesize($_FILES['videofile']['tmp_name']);

				if($size > MAX_SIZE*1024) {

					$bad = '<p class="bad">Video too large.</p>';
					$form = $upload;

				}

				$time = time();
				$image_name = $time . '.' . $extension;
				$newname = "uploads/properties/landlord_files/videos/" . $image_name;

				if(move_uploaded_file($_FILES['videofile']['tmp_name'], $newname)) {
					if($property->add_video($time, 'flv', $_POST['videotitle'])) {
						$srcFile = 'uploads/properties/landlord_files/videos/' . $image_name;
						$destFile = 'uploads/properties/landlord_files/videos/' . $time . '.flv';
						$ffmpegPath = "/usr/bin/ffmpeg";
						$flvtool2Path = "/usr/bin/flvtool2";

						$ffmpegObj = new ffmpeg_movie($srcFile);
						$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
						$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
						$srcFPS = $ffmpegObj->getFrameRate();
						$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
						$srcAR = $ffmpegObj->getAudioSampleRate();

						$img = $image_name;
						$ff_frame = $ffmpegObj->getFrame(1);

						if($ff_frame) {
							$gd_image = $ff_frame->toGDImage();
							if($gd_image) {
								imagepng($gd_image, $img);
								imagedestroy($gd_image);
								$property->add_image($img, 'png', 'frame_shot');
							}
						} 

						exec($ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile);
						@unlink($newname);
						function makeMultipleTwo ($value) {
							$sType = gettype($value/2);
							if($sType == "integer") {
								return $value;
							} else {
								return ($value-1);
							}
						}
						$ref = 1;
					} else {
						@unlink($newname);
						$bad = '<p class="bad">Video upload failed.</p>';
						$form = $upload;
					}
				} else {
					$bad = '<p class="bad">Video upload failed.</p>';
					$form = $upload;

				}
			}
		}

		if($ref == 1) {
			header('Location: landlord_account.php?page=3');
		}

	} else {
		$form = '<form id="Upload" action="upload_video.php" enctype="multipart/form-data" method="post">
					<h3>Upload a video of your property</h3>
					<label>Video Title</label>
					<input type="text" name="videotitle"><br />
					<input type="file" name="videofile">

					<label>Submit</label>
					<input type="submit" name="submit" value="Upload"><br />
					<a href="landlord_account.php">Skip</a>
				</form>';
	}

	$template = new template();
	$array = array('TITLE' => 'Upload A Video', 'CONTENT' => $form);

	$template->newTemplate($array, 'add_property');
} else {
	header('Location: landlord_account.php');
}
?>

 

Many thanks,

 

James.

Everything, nothing is uploading, nothing is converting. I have had no errors at all, I have also stripped the script and turned it into just a form and the processing script. Still nothing.

 

Many thanks,

 

James.

The biggest problem is that there is nothing that would set $_FILES['imageone'], so all the code dependent on that would be skipped over.

 

You have attempted basic troubleshooting to find out what your code is doing?

Totally didn't notice that. Edited. I have done a debug, I have test all vars and functions except the exec as this is reported to be working already from my hosting company (as I asked them to test the exec function).

 

All is still failing to do anything.

 

The only error I have ever got from the script is

 

Notice: A session had already been started - ignoring session_start() in /var/www/vhosts/yourhomely.co.uk/httpdocs/system/template/template.php on line 1

 

but this has nothing to do with why the upload is failing, right?  :confused:

Many thanks,

 

James.

I have even changed the code to this to get some feedback;

 

<?php session_start();

include 'system/template/template.php';
include 'system/mysql/mysql.php';
include 'system/properties/property.php';

	$mysql = new mysql();
	$mysql->connect();

	$property = new property();


	if($property->landlord_loggedin()) {
		header('Location: login.php');
	}

	function save_log($string) {
		$myFile = "testFile.txt";
		$fh = fopen($myFile, 'w') or die("can't open file");
		$stringData = $string . "\n";
		fwrite($fh, $stringData);
		fclose($fh);
	}
	$_SESSION['N_P_ID'] = 1;
if(isset($_SESSION['N_P_ID']) && !empty($_SESSION['N_P_ID'])) {
	if(isset($_POST['videotitle']) && !empty($_POST['videotitle']) && isset($_FILES['videofile']) && !empty($_FILES['videofile'])) {
		$upload = $bad . '<form id="Upload" action="upload_video.php" enctype="multipart/form-data" method="post">
					<h3>Upload a video of your property</h3>
					<label>Video Title</label>
					<input type="text" name="videotitle"><br />
					<input type="file" name="videofile">

					<label>Submit</label>
					<input type="submit" name="submit" value="Upload"><br />
					<a href="landlord_account.php">Skip</a>
				</form>';
				save_log($upload);
		$extensions = array('mpg', 'avi', 'mpeg');
		define ("MAX_SIZE","10240"); 

		function getExtension($str) {
			$i = strrpos($str,".");
			if (!$i) {
				return "";
			}

			$l = strlen($str) - $i;
			$ext = substr($str,$i+1,$l);

			return $ext;
		}

		if(isset($_FILES['videofile'])) {

			if(!isset($_POST['videotitle'])) {
				$bad = '<p class="bad">Please enter a video title.</p>';
				$form = $upload;
				save_log($bad);
			}

			$filename = stripslashes($_FILES['videofile']['name']);
save_log($filename);
			$extension = strtolower(getExtension($filename));
save_log($extension);
			if(!in_array($extension, $extensions)) {

				$bad = '<p class="bad">Video is incorrect format, please make sure your video format is either mpg/mpeg or avi.</p>';
				$form = $upload;
				save_log($bad);

			} else {

				$size = filesize($_FILES['videofile']['tmp_name']);
save_log($size);
				if($size > MAX_SIZE*1024) {

					$bad = '<p class="bad">Video too large.</p>';
					$form = $upload;
					save_log($bad);

				}

				$time = time();
				$image_name = $time . '.' . $extension;
				$newname = "uploads/properties/landlord_files/videos/" . $image_name;
save_log($newname);
save_log($image_name);
save_log($time);
				if(move_uploaded_file($_FILES['videofile']['tmp_name'], $newname)) {
					if($property->add_video($time, 'flv', $_POST['videotitle'])) {
						$srcFile = 'uploads/properties/landlord_files/videos/' . $image_name;
						$destFile = 'uploads/properties/landlord_files/videos/' . $time . '.flv';
						$ffmpegPath = "/usr/bin/ffmpeg";
						$flvtool2Path = "/usr/bin/flvtool2";
save_log($destFile . ' ' . $srcFile);
						$ffmpegObj = new ffmpeg_movie($srcFile);
						$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
						$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
						$srcFPS = $ffmpegObj->getFrameRate();
						$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
						$srcAR = $ffmpegObj->getAudioSampleRate();

						$img = $image_name;
						$ff_frame = $ffmpegObj->getFrame(1);
save_log($img);
						if($ff_frame) {
							$gd_image = $ff_frame->toGDImage();
							if($gd_image) {
								imagepng($gd_image, $img);
								imagedestroy($gd_image);
								$property->add_image($img, 'png', 'frame_shot');
							}
						} 

						exec($ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile);
						@unlink($newname);

						function makeMultipleTwo ($value) {
							$sType = gettype($value/2);
							if($sType == "integer") {
								return $value;
							} else {
								return ($value-1);
							}
						}

						$ref = 1;
					} else {
						@unlink($newname);
						$bad = '<p class="bad">Video upload failed.</p>';
						$form = $upload;
						save_log($bad);
					}
				} else {
					$bad = '<p class="bad">Video upload failed.</p>';
					$form = $upload;
					save_log($bad);

				}
			}
		}

		if($ref == 1) {
			header('Location: landlord_account.php?page=3');
		}

	} else {
		$form = '<form id="Upload" action="upload_video.php" enctype="multipart/form-data" method="post">
					<h3>Upload a video of your property</h3>
					<label>Video Title</label>
					<input type="text" name="videotitle"><br />
					<input type="file" name="videofile">

					<label>Submit</label>
					<input type="submit" name="submit" value="Upload"><br />
					<a href="landlord_account.php">Skip</a>
				</form>';
	}

	$template = new template();
	$array = array('TITLE' => 'Upload A Video', 'CONTENT' => $form);

	$template->newTemplate($array, 'add_property');
} else {
	header('Location: landlord_account.php');
}
?>

 

And the text file is still completely empty, nothing is happening.

 

Anyone have any ideas?

 

Many thanks,

 

James.

Anyone have any ideas?

 

I'm using my originial code now;

 

<?php session_start();

include 'system/template/template.php';
include 'system/mysql/mysql.php';
include 'system/properties/property.php';

	$mysql = new mysql();
	$mysql->connect();

	$property = new property();


	if($property->landlord_loggedin()) {
		header('Location: login.php');
	}
	$_SESSION['N_P_ID'] = 1;
if(isset($_SESSION['N_P_ID']) && !empty($_SESSION['N_P_ID'])) {
	if(isset($_POST['videotitle']) && !empty($_POST['videotitle']) && isset($_FILES['videofile']) && !empty($_FILES['videofile'])) {
		$upload = $bad . '<form id="Upload" action="upload_video.php" enctype="multipart/form-data" method="post">
					<h3>Upload a video of your property</h3>
					<label>Video Title</label>
					<input type="text" name="videotitle"><br />
					<input type="file" name="videofile">

					<label>Submit</label>
					<input type="submit" name="submit" value="Upload"><br />
					<a href="landlord_account.php">Skip</a>
				</form>';

		$extensions = array('mpg', 'avi', 'mpeg');
		define ("MAX_SIZE","10240"); 

		function getExtension($str) {
			$i = strrpos($str,".");
			if (!$i) {
				return "";
			}

			$l = strlen($str) - $i;
			$ext = substr($str,$i+1,$l);

			return $ext;
		}

		if(isset($_FILES['videofile'])) {

			if(!isset($_POST['videotitle'])) {
				$bad = '<p class="bad">Please enter a video title.</p>';
				$form = $upload;
			}

			$filename = stripslashes($_FILES['videofile']['name']);

			$extension = strtolower(getExtension($filename));

			if(!in_array($extension, $extensions)) {

				$bad = '<p class="bad">Video is incorrect format, please make sure your video format is either mpg/mpeg or avi.</p>';
				$form = $upload;

			} else {

				$size = filesize($_FILES['videofile']['tmp_name']);

				if($size > MAX_SIZE*1024) {

					$bad = '<p class="bad">Video too large.</p>';
					$form = $upload;

				}

				$time = time();
				$image_name = $time . '.' . $extension;
				$newname = "uploads/properties/landlord_files/videos/" . $image_name;

				if(move_uploaded_file($_FILES['videofile']['tmp_name'], $newname)) {
					if($property->add_video($time, 'flv', $_POST['videotitle'])) {
						$srcFile = 'uploads/properties/landlord_files/videos/' . $image_name;
						$destFile = 'uploads/properties/landlord_files/videos/' . $time . '.flv';
						$ffmpegPath = "/usr/bin/ffmpeg";
						$flvtool2Path = "/usr/bin/flvtool2";

						$ffmpegObj = new ffmpeg_movie($srcFile);
						$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
						$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
						$srcFPS = $ffmpegObj->getFrameRate();
						$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
						$srcAR = $ffmpegObj->getAudioSampleRate();

						$img = $image_name;
						$ff_frame = $ffmpegObj->getFrame(1);

						if($ff_frame) {
							$gd_image = $ff_frame->toGDImage();
							if($gd_image) {
								imagepng($gd_image, $img);
								imagedestroy($gd_image);
								$property->add_image($img, 'png', 'frame_shot');
							}
						} 

						exec($ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile);
						@unlink($newname);
						function makeMultipleTwo ($value) {
							$sType = gettype($value/2);
							if($sType == "integer") {
								return $value;
							} else {
								return ($value-1);
							}
						}
						$ref = 1;
					} else {
						@unlink($newname);
						$bad = '<p class="bad">Video upload failed.</p>';
						$form = $upload;
					}
				} else {
					$bad = '<p class="bad">Video upload failed.</p>';
					$form = $upload;

				}
			}
		}

		if($ref == 1) {
			header('Location: landlord_account.php?page=3');
		}

	} else {
		$form = '<form id="Upload" action="upload_video.php" enctype="multipart/form-data" method="post">
					<h3>Upload a video of your property</h3>
					<label>Video Title</label>
					<input type="text" name="videotitle"><br />
					<input type="file" name="videofile">

					<label>Submit</label>
					<input type="submit" name="submit" value="Upload"><br />
					<a href="landlord_account.php">Skip</a>
				</form>';
	}

	$template = new template();
	$array = array('TITLE' => 'Upload A Video', 'CONTENT' => $form);

	$template->newTemplate($array, 'add_property');
} else {
	header('Location: landlord_account.php');
}
?>

 

Still not working thoe, someone please help!  :-[

 

Many thanks,

 

James.

Best guess is that your upload is failing (there's at least 10 different things that could prevent it, from uploads not being enabled on your server to the file size exceeding the limits set in the php.ini) and your code has absolutely no error checking and error reporting/logging logic in it to test if the upload worked before attempting to access any of the uploaded file information.

 

 

I beleive so, how would I tell? The .txt file is still empty meaning that nothing has called the function to write anything to it.

 

Many thanks,

 

James.

 

echo echo echo

 

echo lines in places within your code so you can see what is going on. to tell whether the function is called, add an echo to the function

 

function xyz($abc) {
   echo "IN function xyz. got parameter abc: $abc <br /> \n";

   // continue regular function activity
}

this is just basic troubleshooting. use echo to see what's going on. what logic is or isn't happening? what values are set, what those values are, and what they are supposed to be. we can't just look at your code and say "the problem is line #253". You and us both need to know what's going on and the easiest way to figure that out is to have the code tell us via echo.

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.