![](/img/trans.png)
[英]Uploading .xls file from webserver to Google Drive using PHP code
[英]Uploading a file to the webserver with customization
好的,所以我希望能夠通過PHP將圖像上傳到我的網絡服務器,以用於管理控制面板。 現在,我希望能夠使用文件上傳器上傳圖像,並使用文本框作為將要調用圖像的文件名。 干杯:D
在html中使用標准格式
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Filename: <input name="name" type="text" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
然后是uploader.php文件:
//get the data from the form
$target_path = "uploads/";
$name= $_POST['name'];
$target_path = $target_path . $name;
//this is the script which uploads the file
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded as" . $name;
} else{
echo "There was an error uploading the file, please try again!";
}
您可能要檢查文件是否為圖像..
$max_size=20000; //in kb
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < $max_size)
&& in_array($extension, $allowedExts))
{
//here goes the script to upload the file!!
}else{
echo"The file is not supported";}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.