مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

ghorashi

عضویت از 1395/08/16

آپلود فایل با jquery و html

  • دوشنبه 8 شهریور 1400
  • 13:36
تشکر میکنم

سلام من کد زیر را برای آپلود فایل در وب سایت نوشتم .

<form method="POST" action="upload.php" enctype="multipart/form-data">
       <input type="file" name="myFile" />
       <input type="submit" value="Upload">
   </form>

و این کد php  هم برای آپلود فایل 

<?php

if (!isset($_FILES["myFile"])) {
   die("There is no file to upload.");
}

$filepath = $_FILES['myFile']['tmp_name'];
$fileSize = filesize($filepath);
$fileinfo = finfo_open(FILEINFO_MIME_TYPE);
$filetype = finfo_file($fileinfo, $filepath);

if ($fileSize === 0) {
   die("The file is empty.");
}

if ($fileSize > 3145728) { // 3 MB (1 byte * 1024 * 1024 * 3 (for 3 MB))
   die("The file is too large");
}

$allowedTypes = [
  'image/png' => 'png',
  'image/jpeg' => 'jpg'
];

if (!in_array($filetype, array_keys($allowedTypes))) {
   die("File not allowed.");
}

$filename = basename($filepath); // I'm using the original name here, but you can also change the name of the file here
$extension = $allowedTypes[$filetype];
$targetDirectory = __DIR__ . "\\uploads"; // __DIR__ is the directory of the current PHP file

$newFilepath = $targetDirectory . "/" . $filename . "." . $extension;

if (!copy($filepath, $newFilepath)) { // Copy the file, returns false if failed
   die("Can't move file.");
}
unlink($filepath); // Delete the temp file

echo "File uploaded successfully :)";

در زمان آپلود با ارور 405 مواجه میشم که نمیتونم رفع کنم . 

ظاهرا با فایل php در iis مشکل داره . بعضی جاها هم گفته بودن به فولدر  upload  باید دسترسی full control  بدی . این کا ر رو انجام دادم ولی به نتیجه ای نرسیدم . یک جای دیگه گفته بود در iis باید fastcgi رو فعال کنی که این کار رو نتونستم انجام بدم .

کلا میخوام راه حل چیه ؟ یا اینکه اگر راه حل دیگه ای به غیر از استفاده از php برای دریافت فایل  وجود داره به من معرفی کنید . 

خیلی تو اینترنت جستجو کردم ولی به نتیجه ای نرسیدم که بتونم با اچ تی ام ال و جی کوئری فایل آپلود کنم.

 

HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
Most likely causes:
The request sent to the Web server used an HTTP verb that is not allowed by the module configured to handle the request.
A request was sent to the server that contained an invalid HTTP verb.
The request is for static content and contains an HTTP verb other than GET or HEAD.
A request was sent to a virtual directory using the HTTP verb POST and the default document is a static file that does not support HTTP verbs other than GET or HEAD.
Things you can try:
Verify the list of verbs enabled for the module handler this request was sent to, and ensure that this verb should be allowed for the Web site.
Check the IIS log file to see which verb is not allowed for the request.
Check the failed request tracing logs for additional information about this error. For more information, click here.
Detailed Error Information:
Module   StaticFileModule
Notification   ExecuteRequestHandler
Handler   StaticFile
Error Code   0x80070001
Requested URL   http://localhost:52708/upload.php
Physical Path   D:\WEB Application Programs\Web_upload\Web_upload\upload.php
Logon Method   Anonymous
Logon User   Anonymous
Request Tracing Directory   C:\Users\Ghorashi\Documents\IISExpress\TraceLogFiles\WEB_UPLOAD
 

پاسخ های این پرسش

تعداد پاسخ ها : 0 پاسخ
در حال حاضر هیچ پاسخی ارسال نشده است
کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)