我試圖讓下面的php文件上傳腳本工作,我已經在所有變量上使用了var_dump()和print_r,並且據我所知它應該工作。事實上,這是工作...在我的Windows安裝,我目前正在運行的Ubuntu 12.04,由於某種原因,這不會在我的本地設置工作,我不願意嘗試它的生活,這可能是我的/ tmp /權限?PHP文件上傳返回錯誤
<?php
function upload() {
/* * * check if a file was uploaded ** */
if (is_uploaded_file($_FILES['images']['tmp_name']) && getimagesize($_FILES['images']['tmp_name']) != false) {
/* * * get the image info. ** */
$size = getimagesize($_FILES['images']['tmp_name']);
/* * * assign our variables ** */
$type = $size['mime'];
$imgfp = fopen($_FILES['images']['tmp_name'], 'rb');
$size = $size[3];
$name = $_FILES['images']['name'];
$maxsize = 99999999;
$target_path = "/uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$currentDate = date("Y-m-d");
$target_path = $target_path . $currentDate . ' - ' . basename($_FILES['images']['name']);
/* * * check the file is less than the maximum file size ** */
if ($_FILES['images']['size'] < $maxsize) {
if (move_uploaded_file($_FILES['images']['tmp_name'], $target_path)) {
echo "The file " . basename($_FILES['images']['name']) .
" has been uploaded";
} else {
echo "<div class='error'>There was an error uploading the file, please <a href='../artworkGenerator'>try again!</a></div>";
}
} else {
/* * * throw an exception if image is not of type ** */
throw new Exception("File Size Error");
}
} else {
// if the file is not less than the maximum allowed, print an error
throw new Exception("Unsupported Image Format!");
}
print_r();
}
/* * * check if a file was submitted ** */
if (!isset($_FILES['images'])) {
echo '<p>Please select a file</p>';
} else {
try {
upload();
/* * * give praise and thanks to the php gods ** */
echo '<p>Thank you for submitting</p>';
} catch (Exception $e) {
echo '<h4>' . $e->getMessage() . '</h4>';
}
}
?>
上傳形式:
<form id="uploadForm" enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="99999999" />
<label>Attach file<span class="required"> *</span></label><img style="display:none;float:right;position: relative;top: 45px;right: 5px;" class="logo" src="img/tick.png" alt="logo" />
<hr class="small"/>
<br/>
<input type="file" name="images" id="images" multiple />
<ul id="image-list">
</ul>
<br/><br/>
<hr style="clear:both">
<input class="btn btn-success save" type="submit" id="btn" value="Generate"/>
<div id="invisible" style="display:none;">
</div>
</form>
你能告訴你的文件上傳表單HTML文件夾? –
可能有一些問題,如「upload_max_filesize」或任何其他設置的PHP配置 – PravinS
我已經添加了文件上傳表單.. – dyatesupnorth