0

I've checked many times on various websites like w3schools, php.net, i'm beginner in Php and i have a problem here. I would like to send a php uploader file on my domain folder on public_html / php. I'm not sure how to code the path of my server, like 'website.com/php/uploader' What i would need to code for the path of files uploaded, i reach my file on the web but it writes web page not accessible. To send a php file, is it a good place to put it on public_html ? I want to upload the files in a videos folder, on the server. Also there is some tricks to protect/hide the path of php files ?

Here is a big part of my code :

<!DOCTYPE html>

<html>

<head>

<h1> <title>

Multiple Uploader 

 </title>
</h1>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

<link rel="icon" href="img…" type="image/jpg" sizes="16x16" />

<link rel="stylesheet" type="text/css" href="css/index.php.css">

</head>

<body>

 <?php

  if (isset($_FILES['video']) === true) {
$errors = array();
$allowed_ext = array('mp4', 'ogg', 'webm'); 

$file_name = $_FILES['video']['name'];
$file_ext = strtolower(end(explode('.', $file_name)));  
$file_size = $_FILES['video']['size'];
$file_tmp =  $_FILES['video']['tmp_name'];

if (in_array($file_ext, $allowed_ext) === false) {
   $errors[] = 'Extension not allowed'; 
}      

if ($file_size > 400000000) {
    $errores[] = 'File size must be under 
    400MB'; 
}    

if (empty($errors)) {
    // upload file
if  (move_uploaded_file($file_tmp, 'videos/'.$file_name)) {
    echo 'Files ';
}

} else {
  foreach ($errors as $error) {
  echo $error, '<br />';

  }


  } 




      // Show content details echo '<pre>', print_r($files, true), '</pre>';

 }


 if (isset($_FILES['video2']) === true) {
$errors = array();
$allowed_ext = array('mp4', 'ogg', 'webm'); 

$file_name = $_FILES['video2']['name'];
$file_ext = strtolower(end(explode('.', $file_name)));  
$file_size = $_FILES['video2']['size'];
$file_tmp =  $_FILES['video2']['tmp_name'];

 if (in_array($file_ext, $allowed_ext) === false) {
   $errors[] = 'Extension not allowed'; 
 }     

 if ($file_size > 650000000) {
    $errores[] = 'File size must be under 
    650MB'; 
 }    

 if (empty($errors)) {
    // upload file
 if (move_uploaded_file($file_tmp, 'videos/'.$file_name)) {
    echo 'uploaded! Succeed!';
 }

 } else {
  foreach ($errors as $error) {
  echo $error, '<br />';

  }


 }  




      // Show content details echo '<pre>', print_r($files, true), '</pre>';

 }


 if (isset($_FILES['video3']) === true) {
$errors = array();
$allowed_ext = array('mp4', 'ogg', 'webm', 'zip'); 

$file_name = $_FILES['video3']['name'];
$file_ext = strtolower(end(explode('.', $file_name)));  
$file_size = $_FILES['video3']['size'];
$file_tmp =  $_FILES['video3']['tmp_name'];

 if (in_array($file_ext, $allowed_ext) === false) {
   $errors[] = 'Extension not allowed'; 
 }     

 if ($file_size > 650000000) {
    $errores[] = 'File size must be under 
    650MB'; 
 }    

 if (empty($errors)) {
    // upload file
 if (move_uploaded_file($file_tmp, 'videos/'.$file_name)) {
    echo '';
 }

 } else {
  foreach ($errors as $error) {
  echo $error, '<br />';

  }


 }  




      // Show content details echo '<pre>', print_r($files, true), '</pre>';

 }


 if (isset($_FILES['video4']) === true) {
$errors = array();
$allowed_ext = array('mp4', 'ogg', 'webm', 'zip'); 

$file_name = $_FILES['video4']['name'];
$file_ext = strtolower(end(explode('.', $file_name)));  
$file_size = $_FILES['video4']['size'];
$file_tmp =  $_FILES['video4']['tmp_name'];

 if (in_array($file_ext, $allowed_ext) === false) {
   $errors[] = 'Extension not allowed'; 
 }     

 if ($file_size > 650000000) {
    $errores[] = 'File size must be under 
    650MB'; 
 }    

 if (empty($errors)) {
    // upload file
 if (move_uploaded_file($file_tmp, 'videos/'.$file_name)) {
    echo '';
 }

 } else {
  foreach ($errors as $error) {
  echo $error, '<br />';

  }


 }  




      // Show content details echo '<pre>', print_r($files, true), '</pre>';

 }


?>

<div id="content">

 <form action="index.php" method="POST" enctype="multipart/form-data">

 <input type="file" name="video"> 
 <input type="file" name="video2">
 <input type="file" name="video3"> 
 <input type="file" name="video4">
 <input type="submit" value="Upload">
  <h3 align="left"> *zip* partes bajas </h3>
  <h3 align="left"> Infos : Videos con numeros aceptados. Ejemplo : video1, video2,    
  video 3, etc.
  <br />
  Vacio = Extensions not allowed / Extensiones no apoyadas </h3> 

 </form>

</div>

</body>
user2731506
  • 73
  • 1
  • 9

1 Answers1

1
echo $_SERVER['DOCUMENT_ROOT'];

thats your current path.

if you want to hide the files on the server, put them in a directory that is further up the tree than the public_html/ directory, perhaps in their own videos/ directory

+/directory structure illustrated
|
-videos/
--upload203.mpeg
--upload204.video
-public_html/
--index.php
--upload.php
--view.php

etc..

XaxD
  • 1,429
  • 14
  • 27
  • Thanks! I'll try it right now! i write echo $_SERVER['site...']; i write the name of the folder right ? – user2731506 Sep 13 '13 at 02:10
  • no $_SERVER['DOCUMENT_ROOT'] simply tells you where you are on the server. You will need to edit the value it returns to remove it from the public_html directory. – XaxD Sep 13 '13 at 02:11
  • I've tried that. It wrotes on the web page : Error Code : ERR_CONNECTION_RESET. – user2731506 Sep 13 '13 at 02:30
  • your host might not be allowing you to upload files. have you tested your code on your local machine? – XaxD Sep 13 '13 at 02:32
  • Hi, yes! I've tested it on MAMP Local Server, the code works well on MAMP, it sends the files on the folder videos. How can i allow the upload files ? Do you know ? – user2731506 Sep 13 '13 at 02:34
  • you can try editing the priveleges on the videos/ directory to 664 or something but it sounds like your host does not allow HTTP file uploads. nothin you can do except contact them and get ready to change hosts. – XaxD Sep 13 '13 at 03:09
  • 1
    There is a configured limit (134 217 728) for my shared server, that's why it doesn't work! Now, why it's working on MAMP ? There is a higher limit ? I've touched limits on php.ini, i guess that's why. Is there a way to use MAMP for an Online client to he makes the uploads, i receive the files. etc ? – user2731506 Sep 13 '13 at 19:07
  • 1
    Hi Xax, i've tried with a jpg and it works well. So, it's the file size limit the problem they told me 134217728, so i would be available to upload a video of (34 721 555 octets) no ? Seems wierd to me. – user2731506 Sep 13 '13 at 22:21
  • you could host the upload server somewhere else or change your hosting entirely at this point. there are no solutions SO can offer you to fix this problem that wouldn't result in much worse legal concerns. I'm pretty sure hacking the server to set up a custom configuration is against your hosts ToS ;). – XaxD Sep 14 '13 at 03:30
  • Hi Xax, it is working for videos of 7, 10 minutes. the upload limit is like 185000000 bytes of my web server (shared hosting). But sometimes it uploads and tells Internal server error, something like that, but i receive the files on the server, it's strange. How could i use MAMP to upload files online ? Is it possible ? – user2731506 Sep 17 '13 at 21:03
  • not really possible unless you know a lot about setting up servers and have the ability to host yourself anyway. it is not commonly recommended. – XaxD Sep 18 '13 at 13:39
  • Thanks XaxD. I'll use my uploader and Panel control for big files. All the best!! – user2731506 Sep 19 '13 at 22:42