Author Topic: PHP Upload  (Read 9750 times)

0 Members and 3 Guests are viewing this topic.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
PHP Upload
« on: November 24, 2012, 12:15:44 am »
How can I get video upload set up? I tried using this script I found
Code: [Select]
<?php 
 $uploaded_size 
$_FILES[&#39;uploaded&#39;][&#39;size&#39;];
 
$uploaded_type $_FILES[&#39;uploaded&#39;][&#39;type&#39;];
 
$target "/home/omni/uploads";
 
$allowed =  array(&#39;mp4&#39;,&#39;wmv&#39; ,&#39;avi&#39;,&#39;flv&#39;);
 
$filename $_FILES[&#39;uploaded&#39;][&#39;tmp_name&#39;];
 
$ext pathinfo($filenamePATHINFO_EXTENSION);
 
$target $target basename$_FILES[&#39;uploaded&#39;][&#39;name&#39;]) ; 
 
$ok=1
 
 
//This is our size condition 
 
if ($uploaded_size 209715200
 { 
 echo 
"Your file is too large.<br>"
 
$ok=0
 } 
 
 
//This is our limit file type condition 
 
if (!in_array($ext,$allowed))
 { 
 echo 
"Only Video Files<br>"
 
$ok=0
 } 
 
 
//Here we check that $ok was not set to 0 by an error 
 
if ($ok==0
 { 
 Echo 
"Sorry your file was not uploaded"
 } 
 
 
//If everything is ok we try to upload it 
 
else 
 { 
  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("home/omni/uploads" $_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"];
      
}
    }
 } 
 
?>

and
Code: [Select]
<html><body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
 Please choose a file: <input name="uploaded" type="file" /><br />
 <input type="submit" value="Upload" />
 </form>
</body></html>
Though that doesn't seem to be working. When I try uploading a 10mb avi file it tells me that I need to use a video file. If I take out the condition it says I uploaded a file with no name that is 0kb. I have apache2 and php5. How can I get uploads working where people can only upload files <200mb and that are video files?

I've been trying to learn how to use php and html but I still don't really understand it so it would really help if someone could just explain how to get it set up and what script to use.
I'm hosting it on my server
« Last Edit: November 25, 2012, 05:28:20 pm by ruler501 »
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Rhombicuboctahedron

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 437
  • Rating: +41/-6
    • View Profile
Re: PHP Upload
« Reply #1 on: November 24, 2012, 12:24:08 am »
I doubt this would work, because I believe this is entirely meant for YouTube Direct, but when I compiled it all, I could embed something in a simple html file that led to a YouTube widget.
I wonder if it would be possible to view the source and use it, but I know even less of web programming.
http://omnimagatvtest.appspot.com/omnimagatvtestexample.html

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: PHP Upload
« Reply #2 on: November 24, 2012, 12:28:12 am »
Unfortunately that just seems to link to a javascript file specific to youtube direct. Thanks for linking it though; It reminds me that I forgot to link to where I host this.
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Rhombicuboctahedron

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 437
  • Rating: +41/-6
    • View Profile
Re: PHP Upload
« Reply #3 on: November 25, 2012, 12:11:12 am »
I just started PHP today, so I don’t know very much, but it seemed like the error had to do something with the file type. It didn’t want to register it as accepted.
Also, I think you might be able to upload text with this.
I found this and changed a few things, but it needs to be changed a bi too, because it was meant for images.

Code: [Select]
<html>
<form name="upload" method="POST" action="upload.php">
Title: (limit 50 characters)<br />
<input type="text" name="title" maxlength="32" style="width:200px;" /><br /><br />
Message: (YouTube limits 1000 characters)<br />
<textarea name="message" cols="60" rows="20"></textarea><br /><br />
Upload Image: (.mp4, .wmv, .avi, .flv, and less than 200MB in size.)<br />
<input type="file" name="image" id="image" style="color:#fff;" />
<br /><br />
<input type="submit" name="upload" value="Upload" />
</form>`
</html>

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: PHP Upload
« Reply #4 on: November 25, 2012, 05:23:04 am »
If i can get on my computer today, i'll post what script i'm using, and i'll try to explain it
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: PHP Upload
« Reply #5 on: November 25, 2012, 02:01:35 pm »
Rhombicuboctahedron I know how to get text. I'd probably just ask for a description txt file uploaded alongside. The hard part is linking them together for the admins, though I have ideas on how to do that. Once I get file upload working I'll work on that.

stevon8ter that would be great if you could post that. I am a complete php/web programming noob.
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: PHP Upload
« Reply #6 on: November 25, 2012, 02:07:29 pm »
Ruler, i have a little bit of experience, but more then enough to make file uploads, a little visitor board and admin function, so if you ever need help...

(I'll do the script in 2h or so.. Sorry
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: PHP Upload
« Reply #7 on: November 25, 2012, 02:49:19 pm »
Anything you can do to help would be great. I plan on learning just have never had the time. The only real thing we need is a way for videos to be uploaded and linked with a text file. Then for admins to be able to look at that. I was planning on using ftp for the admins and maybe folders to store the video and text together if I can find a way to make folders and upload files to them.
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: PHP Upload
« Reply #8 on: November 25, 2012, 03:03:00 pm »
Do you mean make folders on your website or do you mean make a folder on the server?
And what do you mean with textfiles?
That you upload a video + textfile and that they have to be linked together?
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: PHP Upload
« Reply #9 on: November 25, 2012, 03:05:23 pm »
Do you mean make folders on your website or do you mean make a folder on the server
Create a folder on the server to store the video and text file in.
And what do you mean with textfiles?
That you upload a video + textfile and that they have to be linked together?
Yeah I was thinking they'd both go in a folder together inside of the uploads directory
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: PHP Upload
« Reply #10 on: November 25, 2012, 03:06:50 pm »
And what do you mean with textfiles?
That you upload a video + textfile and that they have to be linked together?
Yeah I was thinking they'd both go in a folder together inside of the uploads directory
so you mean for every video that's uploaded... create a nex folder?
ie: if i upload 1st video, create a folder of itself called vid1 ?
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: PHP Upload
« Reply #11 on: November 25, 2012, 03:08:33 pm »
Yeah create a folder and put the video and text in it. I don't really care what the folders are named as long as they are all unique names
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: PHP Upload
« Reply #12 on: November 25, 2012, 03:16:46 pm »
Ok, you need the mkdir() command for that, but i'll explain it later...
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: PHP Upload
« Reply #13 on: November 25, 2012, 04:18:17 pm »
1) sorry for double posting but i concidrr this as an update

Html form:
Code: [Select]
<form action="uploader.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" />
</form>

Php script:
Code: [Select]
<?php

$allowedExts 
= array(/*all allowed exts go here*/);
$extension end(explode("."$_FILES["file"]["name"]));
if ((
$_FILES["file"]["size"] < 10485760 /* file size*/) && in_array($extension$allowedExts))
  {
  if (
$_FILES["file"]["error"] > 0)
    {
    echo 
"Return Code: " $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    
$random_digit=rand(0000,9999);
    
$pathnew $random_digit $_FILES["file"]["name"];
    echo 
"Uploaded file name: " $pathnew "<br />";
    echo 
"Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

$path=random_digit;

    if (
file_exists("../upload/ /*or whatever the upload dir is*/" $path "/" $pathnew))
      {
             
$lol 0;
while (
$lol === 0)
{
      
$random_digit=rand(0000,9999);
    
$pathnew $random_digit $_FILES["file"]["name"];

$path $random_digit;

if (
file_exists("../upload/ /* again whatever upload dir is*/" $path "/" $pathnew))
{
$lol 0;
}
else
{
$lol 1;
}
}
      }
    else
      {
     
mkdir($path);

move_uploaded_file($_FILES["file"]["tmp_name"],
      
"upload/" $path "/" $pathnew);
       }
    }
  }
else
  {
  echo 
"Invalid file";
  }
?>


I made a few changes to try to let it work with newdirections, but didn't test it
So please report all errors ;)
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: PHP Upload
« Reply #14 on: November 25, 2012, 05:19:38 pm »
When I use this I'm not getting anything as output. I get a blank page when trying to upload an avi file

Code: [Select]
<?php

$allowedExts 
= array(&#39;mp4&#39;,&#39;wmv&#39;,&#39;avi&#39;,&#39;flv&#39;/*all allowed exts go here*/);
$extension end(explode("."$_FILES["file"]["name"]));
if ((
$_FILES["file"]["size"] < 10485760 /* file size*/) && in_array($extension$allowedExts))
  {
  if (
$_FILES["file"]["error"] > 0)
    {
    echo 
"Return Code: " $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    
$random_digit=rand(0000,9999);
    
$pathnew $random_digit $_FILES["file"]["name"];
    echo 
"Uploaded file name: " $pathnew "<br />";
    echo 
"Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

$path=random_digit;

    if (
file_exists("/home/omni/uploads" $path "/" $pathnew))
      {
             
$lol 0;
while (
$lol === 0)
{
      
$random_digit=rand(0000,9999);
    
$pathnew $random_digit $_FILES["file"]["name"];

$path $random_digit;

if (
file_exists("/home/omni/uploads" $path "/" $pathnew))
{
$lol 0;
}
else
{
$lol 1;
}
}
      }
    else
      {
     
mkdir($path);

move_uploaded_file($_FILES["file"]["tmp_name"],
      
"/home/omni/uploads" $path "/" $pathnew);
       }
    }
  }
else
  {
  echo 
"Invalid file";
  }
?>
Did I do something wrong?
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y