簡體   English   中英

內部服務器錯誤 500 上傳圖片 iOS php

[英]Internal Server Error 500 upload image iOS php

我讀過很多人遇到同樣的問題,所有人都相似並且與我的服務器設置有關,確保圖像目錄具有 755 權限,出於某種原因,我看到我的用戶子文件夾設置為 777,並且我創建了php.ini 文件,我確保我的 upload_max_filesize 設置正確,並且我的 php.ini 有正確的設置。 我從許多不同的教程中嘗試了幾種不同的編碼技術,都輸出了相同的錯誤。

這是我的 NSlog 中的錯誤

myproject[11784:907] test <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
 webmaster@myproject.com and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

這是我的objective-c代碼

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self  dismissViewControllerAnimated:YES completion:NULL];

NSData *dataImage = UIImageJPEGRepresentation(image.image, 0.8f);
NSString *urlString = @"http://www.myproject.com/myphpscript.php";
NSString *filename = [NSString stringWithFormat:@"%@.jpg", [MyClass str]];
NSMutableURLRequest* request= [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *postbody = [NSMutableData data];
[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\"%@.png\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[NSData dataWithData:dataImage]];
[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", @"email"] dataUsingEncoding:NSASCIIStringEncoding]];
[postbody appendData:[[NSString stringWithFormat:@"%@",[MyClass str]] dataUsingEncoding:NSASCIIStringEncoding]];
[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postbody];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString* returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"test %@",returnString);
}

和我的 PHP

<?php
// removed connection 
$mysqli = new mysqli($host, $username, $password, $database);
if ($stmt = $mysqli->prepare("INSERT INTO `user` SET imagepath=? WHERE email=?")) 
{
    $stmt->bind_param('ss', $albumname, $email);

$uploaddir = 'images/users/';
$file = basename($_FILES['userfile']['name']);
$uploadfile = $uploaddir . $file;

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {

}
$albumname = $uploadfile;
    $email = $_POST['email'];
    $stmt->execute();
    $stmt->close(); 
    }


else {
    printf("Prepared Statement Error: %s\n", $mysqli->error);
}

$mysqli->close();
?>

錯誤 500 是服務器端的錯誤。

我建議嘗試從服務器上傳到自身,這樣您可能會獲得更多信息。 還要從您的 Web 服務器、nginx、appache 或您運行的任何內容檢查錯誤日志,您會在那里找到導致錯誤的原因。

雖然我無法從您的代碼中看出 500 錯誤是什么,但我強烈建議您確保您的 PHP ini 文件啟用了錯誤日志記錄並查看日志文件。 大多數情況下 500 錯誤是由 PHP 引擎中的運行時錯誤引起的,它將輸出到日志文件,或者如果您啟用了 display_errors,則會直接輸出到瀏覽器。

一旦您可以讀取日志文件,10 次中有 9 次該錯誤很容易修復。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM