很简单的一个小例子 jQuery Mobile + PHP 通过超全局 $_FILES 上传,然后用move_uploaded_file()方法把上传的图片移动到到本地服务器下的文件夹,
代码如下:
代码如下:
0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; 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"]; } } } ?>
"; } else { echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; 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"]; } } } ?>
代码很简单,但是使用过程中却发现一个问题,自己试了好久都上传不了 询问了小伙伴后,发现问题所在是文件权限不足,从而限制了网页上传图片到文件夹中.所以解决办法就是把文件夹的权限问题解决掉.
代码如下: