PHP图像上传器——截断数组后处理?
好的,我正在为一些客户建立一个基本的图像上传程序,我遇到了一些bug,我正在把我的头发撕下来 在获得$_FILES数组后,我进行了一些处理,以使解析图像更容易,但在后期处理中,我的值被截断 以下是相关的PHP:PHP图像上传器——截断数组后处理?,php,arrays,Php,Arrays,好的,我正在为一些客户建立一个基本的图像上传程序,我遇到了一些bug,我正在把我的头发撕下来 在获得$_FILES数组后,我进行了一些处理,以使解析图像更容易,但在后期处理中,我的值被截断 以下是相关的PHP: function organizeFilesArray(&$file_post) { $file_array = array(); $file_count = count($file_post['name']); $file_keys = array_k
function organizeFilesArray(&$file_post) {
$file_array = array();
$file_count = count($file_post['name']);
$file_keys = array_keys($file_post);
for ($i=0; $i<$file_count; $i++) {
foreach ($file_keys as $key) {
$file_array[$i][$key] = $file_post[$key][$i];
echo "$file_array[$i][$key]";
echo " ... ";
echo "$file_post[$key][$i] ";
}
echo "$file_count ";
}
return $file_array;
}
if(isset($_POST)){
$destinationDirectory = '/Applications/MAMP/htdocs/image_upload/uploads/';
//check if _FILES array is empty or if the file was uploaded via POST
if(!isset($_FILES['ImageFile']) || !is_uploaded_file($_FILES['ImageFile']['tmp_name'])){
die('Something went wrong with Upload!');
}
//clean up the array so I can handle it simply
//$imageArray = organizeFilesArray($_FILES['ImageFile']);
$file_array = organizeFilesArray($_FILES['ImageFile']);
echo" array size pp: " . sizeof($file_array);
foreach($file_array as $file){
//random number to be added after image name
$randomNumber = rand(0, 9999999999);
//access these values by using their index position
//$imageName = str_replace(' ','-',strtolower($file['name']));
$imageName = $file['name']; //get file name
$imageSize = $file['size']; // Obtain original image size
$tempSrc = $file['tmp_name']; // Tmp name of image file stored in PHP tmp folder
$imageType = $file['type']; //Obtain file type, returns "image/png", image/jpeg, text/plain etc.
echo "This is the type before we try: " . $file['type'];
echo "This is the name before we try: " . $file['name'];
echo "This is the size before we try: " . $file['size'];
//make sure filetype is supported
switch(strtolower($imageType)){
case 'image/png':
$createdImage = imagecreatefrompng($file['tmp_name']);
break;
case 'image/gif':
$createdImage = imagecreatefromgif($file['tmp_name']);
break;
case 'image/jpeg':
case 'image/pjpeg':
$createdImage = imagecreatefromjpeg($file['tmp_name']);
break;
default:
die('Unsupported File!:'.$imageType); //output error and exit
}
函数OrganizeFileArray(&$file\u post){
$file_array=array();
$file_count=count($file_post['name']);
$file\u keys=数组\u keys($file\u post);
对于($i=0;$i来说,您可能只是在分解一个上载的文件
尝试更改:
$file_array = organizeFilesArray($_FILES['ImageFile']);
公正
$file_array = organizeFilesArray($_FILES);
除了我最终不得不完全重新编写函数之外,哈哈,这也是问题的一部分!谢谢!