使用PHP移动上传的文件 [英] Moving an uploaded file using PHP

查看:106
本文介绍了使用PHP移动上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人可以帮我检查一下吗?我已经跟着我在这里找到的信息,仍然不能得到它的工作。我的主机说,现在这应该是可能的,因为权限以前被阻止,并不完全是最有帮助的。
谢谢,我总是可以依靠StackOverflow在需要时提供帮助。 :)

$ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ b $ caption = $ _POST ['caption'];
$ file = $ _FILES ['file'] ['name'];
$ target =images / slider;
if(is_uploaded_file($ _ FILES ['file'] ['tmp_name'])){
$ b $ move_uploaded_file($ _ FILES ['file'] ['tmp_name'],'images / slider /'.$_FILES['file']['name'])或死('无法上传');

require_once('../ includes / dbupcombo.php');

$ query =INSERT INTO PremierSlider(caption,image)values('$ caption','$ file');
mysql_query($ query)或者死(mysql_error());


$ b header(location:http://www.premierdancecentre.com/admin/index.php#mod_image);
}
?>

该脚本运行onclick并返回无法上传。任何帮助,为什么会不胜感激,因为我仍然试图在PHP的良好。 Cheers guys

解决方案

 <?php 

if $ _FILES [file] [error]> 0)
{
echo返回代码:。 $ _FILES [file] [error]。 < br />;
}
else
{
echoUpload:。 $ _FILES [file] [name]。 < br />;
回显类型:。 $ _FILES [file] [type]。 < br />;
回声大小:。 ($ _FILES [file] [size] / 1024)。 Kb< br />;
回显临时文件:。 $ _FILES [file] [tmp_name]。 < br />;
$ b $ if(file_exists(upload /。$ _FILES [file] [name]))
{
echo $ _FILES [file] [名称] 。 已经存在。 ;


$ $ b $ move_uploaded_file($ _ FILES [file] [tmp_name],
upload /。$ _FILES [file] [名称]);
回声存储在:。 上传/。 $ _FILES [ 文件] [ 名称];
}
}


?>


please could someone check this for me? I have followed the info that I found on here and still I cant get it to work. My host says that this should now be possible as the permissions were previously blocked, and are not exactly the most helpful. Thanks, I can always rely on StackOverflow to help out when needed. :)

<?PHP
IF(isset($_POST['submit'])){
    $caption = $_POST['caption'];
    $file = $_FILES['file']['name'];
    $target="images/slider";
    if(is_uploaded_file($_FILES['file']['tmp_name'])){

    move_uploaded_file($_FILES['file']['tmp_name'], 'images/slider/'.$_FILES['file']['name']) or die ('cannot upload');

    require_once('../includes/dbupcombo.php');

        $query = "INSERT INTO PremierSlider (caption, image) values ('$caption','$file')";
        mysql_query($query) or die(mysql_error());


}
header("location: http://www.premierdancecentre.com/admin/index.php#mod_image");
}
?>

The script runs onclick and returns 'cannot upload'. Any help as to why would be greatly appreciated as i'm still trying to get good at PHP. Cheers guys

解决方案

<?php

  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }


?> 

这篇关于使用PHP移动上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆