0

このphpビデオアップロードスクリプトを使用しています。ディレクトリパスを、phpファイルと同じディレクトリで作成したvideoというフォルダーに設定しました。しかし、アップロードされているビデオが見つかりません。

私が頼んだディレクトリに行きませんか?誰かが私を助けてくれるのはなぜですか。

エラーは発生しません。

ありがとう。

HTML:

<form action="upload_videos_process.php" method="post"   enctype="multipart/form-data">
  <label for="file">Filename:</label>
     <input type="file" name="uploadFile" id="uploadFile" />
<br />
<input type="submit" name="submit" value="Upload File" />
</form>

php ファイル:

<?php

//This handles the maximum size for the video file in kbs

define ("MAX_SIZE","500");

//This function reads the extension of the file to ensure that it is an video file

function getExtension($str) {

$i = strrpos($str,".");

if (!$i) { return ""; }

$l = strlen($str) - $i;

$ext = substr($str,$i+1,$l);

return $ext;

}

//This variable handles an error and won't upload the file if there is a problem with it

$errors=0;

//checks if the form has been submitted

if(isset($_POST['Submit']))

{

//reads the name of the file the user submitted for uploading

$video=$_FILES['video']['name'];

//if it is not empty

if ($video)

{

//get the original name of the file from the clients machine

$video_filename = stripslashes($_FILES['video']['name']);

$video_extension = getExtension($filename);

$video_extension = strtolower($extension);

//if it is not a known extension, we will suppose it is an error and will not upload the file, otherwise we will do more tests

if (($video_extension != "mpeg") && ($video_extension != "avi") && ($video_extension != "flv") && ($video_extension != "mov"))

{

echo '<h1>Unknown extension!</h1>';

$errors=1;

}

else

{

//get the size of the video

$size=filesize($_FILES['video']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger

if ($size > MAX_SIZE*1024)

{

echo '<h1>You have exceeded the size limit!</h1>';

$errors=1;

}

//give the video a unique name in case a video already exists with the name on the server
$video_name=time().'.'.$extension;

//assign a folder to save the video to on your server

$newname="video/".$video_name;

//verify that the video has been loaded

$copied = copy($_FILES['video']['tmp_name'], $newname);

if (!$copied)

{

echo '<h1>Copy unsuccessful!</h1>';

$errors=1;

}}}}

//If no errors registered, print the success message

if(isset($_POST['Submit']) && !$errors)

{

echo "<h1>File Uploaded Successfully! Try again!</h1>";

}

?>
4

2 に答える 2

0

あなたは盲目的にすべてが完璧に機能していると思い込んでいます。物事は失敗します。最初のステップ: アップロードで実際に何かが行われたかどうかを確認します。

if ($_FILES['video']['error'] !== UPLOAD_ERR_OK) {
    die("Upload failed with error code " . $_FILES['video']['error']);
}

エラーコードはここで定義されています: http://php.net/manual/en/features.file-upload.errors.php

copy()同様に、アップロードが成功したことを確認したら、アップロード ファイルには使用しないでください。理由としてmove_uploaded_file()があります。サーバー上でファイルが改ざんされていないことを確認するための追加のセキュリティ チェックがあり、実際にファイルを移動します。copy() は、ファイルシステムのハウスキーピングを行うのではなく、ファイルを複製しているため、特に大きなファイルでパフォーマンスを低下させる可能性があります。

また、ユーザーがファイル名を改ざんしないことを信頼しています。悪意のあるユーザーがアップロードする前に行うことを防ぐ方法はren nastyvirus.exe cutekittens.aviもありません。ファイル名が変更されているだけなので、スクリプトは喜んでその .exe を受け入れます。これを回避するには、サーバー側の MIME 検出 (例: http://www.php.net/manual/en/book.fileinfo.phpここにリンクの説明を入力) を使用します。ユーザーからのものは決して信用しないでください。

于 2013-01-30T14:35:58.340 に答える
0

PHP の設定で大きなファイルのアップロードが許可されていない可能性があります。設定してみる

upload_max_filesize = 500M

または、php.ini で 500M を超える場合もあり、コメントでここに記載されているように、エラーを有効にします

ini_set('display_errors', 1);
ini_set('error_reporting', 8191); 
于 2013-01-30T14:41:05.800 に答える