jamesxg1 Posted October 4, 2010 Share Posted October 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/ Share on other sites More sharing options...
.josh Posted October 4, 2010 Share Posted October 4, 2010 problem is on line 42 Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1118970 Share on other sites More sharing options...
jamesxg1 Posted October 4, 2010 Author Share Posted October 4, 2010 Hiya mate, Thanks for a prompt reply. Line 42 in whitespace, blank? Is that what the problem is, it being whitespace? Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1118971 Share on other sites More sharing options...
jamesxg1 Posted October 4, 2010 Author Share Posted October 4, 2010 I have just tested the function and it seems to be working ok? Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1118972 Share on other sites More sharing options...
premiso Posted October 4, 2010 Share Posted October 4, 2010 Reading between the lines, you need to tell us "WHAT" isn't working and any possible errors, and what you have tried to get it working. No one is going to blindly go through all that code to find your mistake. Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1118975 Share on other sites More sharing options...
jamesxg1 Posted October 4, 2010 Author Share Posted October 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1118977 Share on other sites More sharing options...
PFMaBiSmAd Posted October 4, 2010 Share Posted October 4, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1118986 Share on other sites More sharing options...
jamesxg1 Posted October 4, 2010 Author Share Posted October 4, 2010 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? Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1118995 Share on other sites More sharing options...
jamesxg1 Posted October 4, 2010 Author Share Posted October 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1119008 Share on other sites More sharing options...
BlueSkyIS Posted October 4, 2010 Share Posted October 4, 2010 BASIC troubleshooting. Is the code calling the function to write the string? Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1119013 Share on other sites More sharing options...
jamesxg1 Posted October 4, 2010 Author Share Posted October 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1119023 Share on other sites More sharing options...
jamesxg1 Posted October 4, 2010 Author Share Posted October 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1119090 Share on other sites More sharing options...
jamesxg1 Posted October 5, 2010 Author Share Posted October 5, 2010 BUMP Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1119228 Share on other sites More sharing options...
PFMaBiSmAd Posted October 5, 2010 Share Posted October 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1119241 Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2010 Share Posted October 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215141-can-anyone-see-anything-wrong-with-my-code/#findComment-1119267 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.