douyou2234 2013-04-29 20:14
浏览 15

上传文件上传任何内容

My Form is simple and I thought the uploading php was simple, but when i test it the results are unusual. I can upload any file and any size and it will Work. I thought i had written it to restrict certain files and sizes...Where am I going wrong?

Form:

 <form enctype="multipart/form-data" action="upload_file.php" method="POST">
 Please choose a file: <input name="uploaded" type="file" /><br />
 <input type="submit" value="Upload" />
 </form> 

upload_file.php:

    $target = "uploads/"; 
    $target = $target . basename( $_FILES['uploaded']['name']) ; 
    $ok = 1; 
    $uploaded = $_POST['uploaded'];
//This is our size condition 
    if ($uploaded_size > 3000){ 
        echo "Your file is too large.<br>"; 
        $ok=0; 
    } 

//This is our limit file type condition 
    if ($uploaded_type == "text/php"){ 
        echo "No PHP files are allowed for upload.<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(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ 
            echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; 
        } 
        else{ 
            echo "Sorry, there was a problem uploading your file."; 
        } 
    }
  • 写回答

3条回答 默认 最新

  • dongping4901 2013-04-29 20:16
    关注

    Your code is outright wrong. Nowhere do you define $uploaded_size, $uploaded_type, etc... so the code boils down to:

    if ($uploaded_size > 3000 {
    

    is equivalent to

    if (0 > 3000) {  // undefined variables are typecast to 0
    

    which evaluates to false, so $ok stays 1 and no error is triggered.

    I STRONGLY suggest you read the PHP manpages on handling file uploads: http://php.net/manual/en/features.file-upload.php

    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数