duaabhuv188411 2015-10-02 03:23
浏览 76
已采纳

使用PHP服务器将文件上传到Web,无法正常工作

I am running a php server for test purposes on 127.0.0.1:8080, and I am trying to save an image to "web" with save2web.php:

  if (isset($_FILES)){
  //put parameters in variables
  $filename = $_FILES['file']['name'];
  $fileTempName = $_FILES['file']['tmp_name'];
  $fileType = $_FILES['file']['type'];
  $fileSize = $_FILES['file']['size'];
  $fileError = $_FILES['file']['error'];

//if the file is a JPG and under 400K, proceed:
if (($fileType == "image/jpeg") && ($fileSize < 400000)){
    //if there's a file error, print it:
    if ( $fileError > 0){
        echo "Return Code" . $fileError . "<br />";
    }
    //if there's no error, print some HTML about the file:
    else {
        echo "Upload: " . $fileName . "<br />";
        echo "Type: " . $fileType . "<br />";
        echo "Size: " . ($fileSize/1024) . " Kb<br />";
        echo "Temp file: " . $fileTempName . "<br />";

        //if the file already exists,
        //delete the previous version:
        if (file_exists($fileName)){
            unlink($fileName);
        }
        //move the file from the temp location to
        //this directory:
        move_uploaded_file($fileTempName, $fileName);
        echo "Uploaded file stored as: ".$filename;
        }
    }
    //if the file is not a jpg or too big, say so:
    else{
        echo "File is not a JPEG or too big.";
    }
}
 ?>

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

when I run the script on the browser, however, I get:

 Upload: 
 Type: image/jpeg
 Size: 45.728515625 Kb
 Temp file: /private/var/tmp/phpEgyvKC

Warning: move_uploaded_file(): Filename cannot be empty in /Users/me/Documents/CODE/Processing/sketches_3/sketches/apps/NetworkedCat_ImageCaptureUpload/save2web.php on line 31

Warning: move_uploaded_file(): Unable to move '/private/var/tmp/phpEgyvKC' to '' in /Users/me/Documents/CODE/Processing/sketches_3/sketches/apps/NetworkedCat_ImageCaptureUpload/save2web.php on line 31 Uploaded file stored as: Peti2.jpg

"line 31" is move_uploaded_file()

this doesn't seem to be a permission issue, because I have changed permissions to chmod 777 on /private/var/tmp, as well as on destination folder

what am I missing?

  • 写回答

2条回答 默认 最新

  • doumou8527 2015-10-02 09:39
    关注

    set your path where you want to upload file

    $path = 'your folder path';

    move_uploaded_file($fileTempName, $path.$fileName);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化