0

我在 w3schools、php.net 等各种网站上检查了很多次,我是 Php 的初学者,我在这里遇到了问题。我想在 public_html / php 上的域文件夹中发送一个 php 上传文件。我不知道如何编码我的服务器的路径,比如'website.com/php/uploader' 我需要为上传文件的路径编码,我在网上找到我的文件,但它写的网页不是无障碍。要发送一个 php 文件,将它放在 public_html 上是不是一个好地方?我想将文件上传到服务器上的视频文件夹中。还有一些技巧可以保护/隐藏 php 文件的路径?

这是我的代码的很大一部分:

<!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>
4

1 回答 1

1
echo $_SERVER['DOCUMENT_ROOT'];

这就是你当前的路径。

如果您想隐藏服务器上的文件,请将它们放在比 public_html/ 目录更靠树的目录中,也许在他们自己的 videos/ 目录中

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

ETC..

于 2013-09-13T02:07:40.623 回答