Jump to content


Php upload script for videos?


7 replies to this topic

#1 cupteadesign

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 25 January 2007 - 04:34 PM

Hey can anyone tell me about a good tutorial for a script to upload videos?

Been looking all over, all for damn images :D !


Thanks!


#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 25 January 2007 - 04:41 PM

Uploading a video would be the exact same procedure as uploading images, only you would change any extension limitations, and you would most probably have to worry about file size upload limited by the server itself (would have to check with your host if you don't have access to php.ini).

#3 cupteadesign

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 25 January 2007 - 04:48 PM

View PostDemonslay, on Jan 25 2007, 04:41 PM, said:

Uploading a video would be the exact same procedure as uploading images, only you would change any extension limitations, and you would most probably have to worry about file size upload limited by the server itself (would have to check with your host if you don't have access to php.ini).


Hey man,

I tried a few of them I found on the web change the file type and sizes and it wouldnt work. Like it would just keep uploading and uploading like it was hung up.......


point of in any direction would be good :D Thanks.

#4 cupteadesign

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 25 January 2007 - 05:14 PM

View Postcupteadesign, on Jan 25 2007, 04:48 PM, said:

View PostDemonslay, on Jan 25 2007, 04:41 PM, said:

Uploading a video would be the exact same procedure as uploading images, only you would change any extension limitations, and you would most probably have to worry about file size upload limited by the server itself (would have to check with your host if you don't have access to php.ini).


Hey man,

I tried a few of them I found on the web change the file type and sizes and it wouldnt work. Like it would just keep uploading and uploading like it was hung up.......


point of in any direction would be good :D Thanks.


GOT IT, person who wrote it forgot something.

#5 cupteadesign

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 27 January 2007 - 10:19 AM

Hey,

Trying to make a php upload script for videos but it doesnt seem to be working....


can someone help me out?

I so far have for the HTML:

[quote]<html>
<head>
</head>
<body>
<center>
<form enctype="multipart/form-data" action="process_upload.php" method="POST">
Send this file: <input name="file" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</center>
</body>
</html>[/quote]AND FOR THE PHP:
[quote]<center> <?php

function generate_rand($l){
$c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
for($i=0; $i<$l; $i++)
{
$rand.= $c[rand()%strlen($c)];
}
return $rand;
}

$uploaddir = "videos/";
$maxfilesize = 104857600; // 100 megabyte
$filename = $_FILES['file']['name'];
$filesize = $_FILES['file']['size'];
$filetmpname = $_FILES['file']['tmp_name'];
$valid = array (".swf",".flv",".wmv",".mov",".avi");
if ($filename) {
$error = "";
if ($filesize == 0) {
$error .= "The submitted file was invalid.<br />";
}
$type = strtolower(strstr($filename, '.'));
if (!in_array($type, $valid)) {
$error .= "The submitted file was of invalid type.<br />";
}
if ($filesize>$maxfilesize) {
$error .= "The submitted file was larger than 100 Megabytes.<br />";
}
$randnum = generate_rand(10);
$randnum .= $type;
$file_exists = true;
while ($file_exists) {
if (file_exists("$uploaddir$randnum")) {
$randnum = generate_rand(10);
$randnum .= $type;
}else{
$file_exists = false;
}
}
if ($error == "") {
if (move_uploaded_file($filetmpname, "$uploaddir$randnum")) {
chmod("$uploaddir$randnum", 0644);
echo "Your file was successfully uploaded!<br />";
echo "<a href='".$uploaddir.$randnum."'>Click here to go to your upload!</a>";
} else {
echo "Your file could not be uploaded.";
}
}else{
echo $error;
}
}else{
echo "No file was uploaded";
}
?>
</center>[/quote]

Thanks guys!!!

#6 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 27 January 2007 - 01:06 PM

Please stick to one topic.

#7 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 27 January 2007 - 03:57 PM

You know the code you've provided is just about completely useless if you don't actually tell us what is going on and what happens when you run it, it saves us alot of time from trying to figure out if it might be your server's configuration or something, and helps narrow down the problem.

#8 smart-coder

    Young Padawan

  • Members
  • Pip
  • 16 posts

Posted 29 January 2007 - 08:26 PM

<html>
<body> <form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form> </body>
</html>

^^ Thats the HTML form ^^

<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
	{
	echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
	}
  else
	{
	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("upload/" . $_FILES["file"]["name"]))
	  {
	  echo $_FILES["file"]["name"] . " already exists. ";
	  }
	else
	  {
	  move_uploaded_file($_FILES["file"]["tmp_name"],
	  "upload/" . $_FILES["file"]["name"]);
	  echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
	  }
	}
  }
else
  {
  echo "Invalid file";
  }
?>

^^ Thats upload_file.php

Of course you have to modify the directory and the file type but I'm 100% sure that code will work.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users