如何使用Ajaxupload Codeigniter在上传过程中获取图像宽度?

时间:2016-05-06 11:25:30

标签: php html css codeigniter

我想在上传图片中获取图片宽度尺寸。

代码:

private void setRecurringAlarm(Context context) {

        Calendar updateTime = Calendar.getInstance();
        updateTime.setTimeZone(TimeZone.getDefault()); 
        Intent downloader = new Intent(context, NotificationServiceReceiver.class);
        downloader.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 123546, downloader, PendingIntent.FLAG_CANCEL_CURRENT);

        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), REPEAT_TIME, pendingIntent);


    }

但是当我打印

for ($i = 0; $i < $number_of_files; $i++) {
    $_FILES['file']['name'] = $files['file']['name'][$i];
    $_FILES['file']['type'] = $files['file']['type'][$i];
    $_FILES['file']['tmp_name'] = $files['file']['tmp_name'][$i];
    $_FILES['file']['error'] = $files['file']['error'][$i];
    $_FILES['file']['size'] = $files['file']['size'][$i];
    $_FILES['file']['image_width'] = $files['file']['image_width'][$i];

    $this->image_lib->initialize($config);
    $this->image_lib->watermark();

    if (!$this->image_lib->watermark()) {
        echo $this->image_lib->display_errors();
}

它显示如下

print_r($_FILES['file']);

无图像宽度显示。

怎么做?

1 个答案:

答案 0 :(得分:1)

您可以使用以下内容: -

$file = $_FILES["file"]['tmp_name'];
list($width, $height) = getimagesize($file);

if($width > "180" || $height > "70") { // You can add your logic
    echo "Error : image size must be 180 x 70 pixels.";
    exit;
}

它可能对你有帮助。