Jump to content

[SOLVED] Uploaded FLV from script


helpthanks

Recommended Posts

Hi helpful people.  Thanks in advance.  I'm a php newbie having a problem that I would categorize as peculiar, but perhaps there is an obvious solution.  I am using php to allow a user to upload an flv file.  This flv is then referenced by an swf through xml.  An html page is dynamically generated, embedding the swf.  The original video is supposed to play on the generated html page.  (Less boring version: FLV -> web page.) 

 

The process works fine locally, but when I attempt to upload remotely, the flv cannot be read in.

 

Here's the weird part: when I download the flv that gets uploaded onto the server, don't mess with it all, but then re-upload it manually, the web page works without issue.  In other words, if I download the uploaded file and then upload it again through ftp, my video plays.  So my process of uploading, which I am sure I must be doing mistakenly, is somehow preventing the file from being read.

 

Here are the relevant parts of two files:

 

<form enctype="multipart/form-data" action="flvUploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

/* UPLOAD TO SERVER */
$target_path = "uploads/". $name_noExt ."/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";   

 

Please let me know if more information is required.  Thanks again.

Link to comment
https://forums.phpfreaks.com/topic/113835-solved-uploaded-flv-from-script/
Share on other sites

Hi, thanks for the reply.  The flv file does seem to get uploaded to the correct path.  However, when I navigate to the web page, the video cannot be found (i.e., more or less a blank video plays.)  But it is in the directory.  I download the uploaded flv from the same directory and then re-upload it to make the video work.

 

In other words, it's there, but there's something funky about it. And that something is fixed with a manual upload..

 

Following is a bit more of the code for a better sense of what's going on (I do have $name_noExt defined):

 

<?php
/* REMOVES FILE EXTENSIONS */
function ridExtensions($thefile) {

if (strpos($thefile,".")===false) {
	return $thefile;
}

else {
	return substr($thefile, 0, strrpos($thefile,"."));
}
}

$name1 = basename( $_FILES['uploadedfile']['name']);
$name_noExt = ridExtensions($name1);


/* MAKE NEW DIRECTORY */
mkdir("uploads/" . $name_noExt);


/*COPY SWF*/
$file = 'xmlPlayer.swf';
$newfile = "uploads/" . $name_noExt . "/xmlPlayer.swf";

if (!copy($file, $newfile)) {
    echo "failed to copy" . $file . "\n";
}

/*COPY SKIN*/
$file = 'SkinOverPlayStopSeekFullVol.swf';
$newfile = "uploads/" . $name_noExt . "/SkinOverPlayStopSeekFullVol.swf";

if (!copy($file, $newfile)) {
    echo "failed to copy" . $file . "\n";
}


/* UPLOAD TO SERVER */
$target_path = "uploads/". $name_noExt ."/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";




/* WRITE TO XML */
$myFile = "uploads/" . $name_noExt . "/content.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
		<rss>
		<channel>

			<item>
				<title>$name1</title>
			</item>

		</channel>
		</rss>";

fwrite($fh, $stringData);
fclose($fh);


/* WRITE TO HTML */
$myFile2 = "uploads/" . $name_noExt . "/" . $name_noExt . ".html";
$fh2 = fopen($myFile2, 'w') or die("can't open file");
$stringData2 = "

<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html;charset=ISO-8859-1\">
<title>Test</title>
<meta name=\"description\" content=\"Test\">
<style type=\"text/css\"> 

html { 
height:100%; /* fix height to 100% for IE */
max-height: 99%; /* fix height for other browsers */ 
padding: 0; /*remove padding */
margin: 0; /* remove margins */
border: 0; /* remove borders */
overflow: hidden; /*get rid of scroll bars in IE */
overflow-y: hidden;
overflow-x: hidden;
} 

body { 
height: 100%; /* fix height to 100% for IE */
max-height: 99%; /* fix height for other browsers */ 
padding: 0; /*remove padding */
margin: 0; /* remove margins */
border: 0; /* remove borders */
hide overflow: hidden from IE5/Mac
overflow: hidden; /*get rid of scroll bars in IE */
overflow-y: hidden;
overflow-x: hidden;
}

/*
table { 
height: 100%; 
width: 100%; 
text-align: center; 
}
*/

</style>
</head>
<body leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" scroll=\"no\">
<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"100%\" height=\"100%\">
<param name=\"movie\" value=\"xmlPlayer.swf\">
<param name=\"quality\" value=\"high\">
<param name=\"menu\" value=\"false\">
<param name=\"scale\" value=\"noscale\">
<embed src=\"xmlPlayer.swf\" width=\"100%\" height=\"100%\" scale=\"noscale\" quality=\"high\" menu=\"false\"  pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\">
</embed>
</object>
</body>
</html>


";

fwrite($fh2, $stringData2);
fclose($fh2);


/*ERROR UPLOADING */
}
else{
    echo "There was an error uploading the file, please try again!";
}
?>

 

My first hunch was that it was a permissions issue because, again, it works on a local server.  I am not too sure what I should change with permissions settings though.  I do have sufficient permissions to write to the server, but perhaps insufficient permissions to write correctly.  What would you think I might change/add?

 

I didn't get any errors when I added the error reporting line.

 

Thanks again for the help.

Hi.  I suppose I should specify that I am writing this script to work on a Yahoo small business server.  The code works on my local apache server.

 

I found this little tidbit on the Yahoo Small Business page, though:

 

 

"To change the read or write permissions of a file, you can use the PHP function chmod(). To make a file readable and writable for the owner, and readable for everybody else, for example,you might create code like this:

 

    chmod ("/directory/file.php", 0644);

 

Please note that you will not be able to change the file permissions of any of your files to make them executable. You can run your PHP scripts, which are indicated by the .php file extension, without making them executable."

 

 

What do you think (adding the chmod 0777 statement didn't seem to work)?

 

P.S. - Yeah, thanks for the call for contribution.

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.